YGOFreak1997 wrote:In the last two functions you posted, you define "object" and "platform" as arguments. What "Type" are they?
First of all, and very importantly, I never defined object or platform in my code.
A definition defines something (a variable or function), and because I never declared either variable, neither are defined. You don't know what they are, and neither does the interpreter (the program, if you like)
It is assumed from the indices (or keys) used in withinrect that :
- object is of type table and contains at least numbers x, y as in :
- platform is of type table and contains at least numbers x, y, w, h as in :
Code: Select all
platform= {x = 128, y = 0, w = 256, h = 32}
And platforms is an array (a base-1 linear-number-indexed table, sometimes called non-dictionary or auto-indexed) containing instances of the platform table, or at least tables which contain platform's minimum set of values.
It could be initialized with :
Code: Select all
platforms = {} -- global platforms, an empty table
function newplatform() return {x = 128, y = 0, w = 256, h = 32} end -- a function which defines a new table and returns it
love.load = function()
i = 1
while i <= 10 do
platforms[i] = newplatform() -- an index for a new platform in platforms, and a new platform as its value
i = i + 1
end
end
Of course, all the platforms returned by newplatform() have the same position and dimensions, so you will want to pass it some arguments to get the platforms you want.