hey guys, I am really stuck with this one. and I would really appreciate some help. I think I am just not use to the syntax. using a for loop, I spawn 10 objects. I want to label them each 1,2,3,4,1,2,3,4,5. I want to start the count over so that I can place all the objects with a 1 on one side of the screen and 2 on another part of the screen etc.
Here is my code.
local spawnTable = {}
[lua]–Function to spawn an object
local function spawn(params)
local object = display.newImage(params.image)
physics.addBody (object, {density = 1})
–Set the objects table to a table passed in by parameters
object.objTable = params.objTable
–Automatically set the table index to be inserted into the next available table index
object.index = (#object.objTable + 1)
–Give the object a custom name
object.myName = object.index
–Insert the object into the table at the specified index
object.objTable[object.index] = object
return object
end
–Create 2 spawns
for i = 1, 5 do
local spawns = spawn(
{
image = “green.png”,
objTable = spawnTable,
}
)
end
–Now print the names of both created spawns
for i = 1, #spawnTable do
print(spawnTable[i].myName)
spawnTable[i] = object
print(spawnTable[i])
– spawnTable[1].y = 300
end[/lua]
Any help at all would be great. Thanks tons in advance!
SM
*Peach: Edited this to add in < lua > tags and make code readable
[import]uid: 79586 topic_id: 28529 reply_id: 328529[/import]
[import]uid: 52491 topic_id: 28529 reply_id: 115358[/import]