I'm try to make an array of objects to hold my box2d objects, but I'm new to lua and not sure how to do this.
Here is an example of what I'm wanting to do.
local my_objects = {}
for i = 0, 9 do
my_objects[i].body = world:createBody(
my_objects[i].shape = b2.CircleShape.new(0,0, radius)
-- etc.
end
But I get the error: "attempt to index field '?' (a nil value)"
I assume it's something to do with my .body and .shape not being setup correctly but I'm not sure how to do it and also not even familar enough with Lua to know how to search google for an answer because I don't know what these things are... is my_objects a Table ... what is the .body part of the table, a property or a field?
Thanks in advanced!
Comments
Likes: antix, vitalitymobile
https://deluxepixel.com
for i = 1, 10 do
or if you like to keep for i = 0, 9 do , you can using my_objects[#my_objects + 1] as the index inside the loop. But "for i = 1,10 do" is more natural and readable so i comment you using that way.
@hgy29 each time I edit code snippets, it generates so much span and destroys the format. I insert the code by using the symbol from the editor and then choose "code" from the drop-down.
Likes: SinisterSoft
Likes: vitalitymobile
https://deluxepixel.com