Sorry for the topic hijack, noway!
No problem. It's interesting to follow.
Besides, it keeps the topic up
These are not mistakes, but it just looks like you're coming from a language other than Lua:
Indeed, I don't have much experience with Lua, and so I'm unaware of some of the common practices and most likely I do some things not the "Lua way". It seems to me, that Lua favors make-it-from-scratch-for-this-particular-case approach, whereas I tend to use more universal ready-to-go solutions. This sometimes overcomplicates things...
you really want to make sure your tutorial code is so simple
that everybody reading it will say "yes, this is clearly the easiest way to make breakout".
That's why I recommend avoiding OOP altogether.
Probably you are right that OOP should not be used unless absolutely needed.
On the other hand, I don't think that declaring a class should be such a big deal.
Once you understand, how __index works, it's not a problem any longer.
Note that setfenv is not commonly used (at least I don't see it that often)
except for peculiar things like loading Lua code from untrusted locations.
I understand it can be used to make modules too...
IMO it's just not necessary to use 'setfenv' in this case.
I've picked it from Programming in Lua ( 3rd ed. , sec. 15.3;
relevant excerpt )
In short, this allows to avoid declaring all functions local, or prefixing them with the module name (in the case of classes, the latter is unavoidable though) .
Code: Select all
local Gamestate = require "gamestate"
menu = {} -- you can safely delete this
game = {} -- and this line
local menu = require "menu"
local game = require "game"
In part 9, yes.
But in general, gamestates can circularly require one another and it becomes necessary to declare them in advance.
Or better yet:
Code: Select all
function Ball:draw()
love.graphics.circle( 'line', self.position.x, self.position.y, self.radius, 16)
end
I use a simple test in cases like this: "Six months from now, would I be able to tell, what this '16' means" ?
I had to add the local variable.
These are not mistakes, but it just looks like you're coming from a language other than Lua:
Code: Select all
function Ball:draw()
local segments_in_circle = 16
love.graphics.circle( 'line', self.position.x, self.position.y, self.radius, segments_in_circle )
end
Can become:
Code: Select all
local segments_in_circle = 16
function Ball:draw()
love.graphics.circle( 'line', self.position.x, self.position.y, self.radius, segments_in_circle)
end
If this is for perfomance/memory reasons, I would prefer to avoid such optimization tweaks, and leave them
to more advanced tutorial.
If you decide to stick with Vrld's libraries (which are very good) then...
Code: Select all
vector( platform_starting_x_pos + o.separation_from_platform_center.x,
platform_starting_y_pos + o.separation_from_platform_c
enter.y )
...you might as well go crazy with the vector operators:
Code: Select all
local platform_starting_pos = vector(500, 500)
....
o.position = o.position or (platform_starting_pos + o.separation_from_platform_center)
Yes, this probably should be corrected.
It first appears in the part 16. I'm surprised, that someone got this far
I'll try to fix it.