Accessing previous element in a table without indices
I made a table of floor elements:
map.list = {}
--first element
firstfloor = {}
firstfloor.x = 50
firstfloor.y = 800
firstfloor.width = 500
firstfloor.height = screenHeight - firstfloor.y
table insert(map.list,firstfloor)
Now i need to make a constructor for next floors. The "x" value is simply
previous floor's "x" position + it's width.
function map:newFloor(x,y,width)
local floor = {}
floor.x = ??? --previous floor's x + previous floor's width
floor.y = y
floor.width = width
floor.height = screenHeight - floor.y
table.insert(map.list,floor)
return floor
end
As you can see there are no indices here. How can i access previous
element's values?
No comments:
Post a Comment