I think that’s the right title. What I’m trying to do is use a function that spawns stuff on a timer and that each thing it spawns is set like [1], [2], [3] etc so that later I can make another function that controls all of the items spawned. Here’s a simple example:
balloon = {}
local i = 1
local function spawnStuff()
if spawnTrue == true then
local randomPos = math.random ( 0, 320 )
balloon[i] = display.newImage( "something.png" )
balloon[i].x = randomPos
balloon[i].y = 230
balloon[i].myName = "balloon"
physics.addBody(balloon[i] , "dynamic", { radius = 17 })
i = i + 1
end
end
timer.performWithDelay( 500, spawnStuff, 500 )
The way I see this function is every 0.5 seconds it should create a new balloon, and that balloon should be indexed as balloon[i] where i = i + 1 after every function. So shouldn’t every balloon that gets spawned be indexed balloon[1], balloon[2] etc ? But when I try to do something with balloon[2] it doesnt work, I get an error because it doesnt exist from the start. I did balloon[1].myName = “balloon” that didnt help. How would I make it work? What I’m trying to do is a more advanced version of the ‘create your own game in 8 minutes’ mostly for practice purposes. I have this :
local function moveStuff(event)
local ball = event.target
ball:applyLinearImpulse( 0, -0.2, event.x, event.y )
end
balloon:addEventListener("touch", moveStuff )
Ive tried a lot of things nothing seems to work. How do I give each balloon spawned a unique identifier that I can later call, and how do I make it so for an eventListener I only have to write one line of code for all the balloons to work. hope im making sense, thanks in advance for any help [import]uid: 77199 topic_id: 24671 reply_id: 324671[/import]
[import]uid: 52491 topic_id: 24671 reply_id: 100064[/import]