I’m having troubles removing transition objects in my game. During a power up, the player gets to shoot 5 bullets. The problem is, only the initial bullet gets removed, the other 4 just sit there. My terminal gives the error on the transition.to “lua:334: attempt to index global ‘bullet’ (a nil value)”. But I obviously can’t nil it out. What should I do to correct this?
[code]
local powerup1 = function()
powerup1 = true
local bullets = 5
local firebutton = display.newImage(“trigger.png”)
firebutton.x = 420
firebutton.y = 255
firebutton.isVisible = true
localGroup:insert(firebutton)
local fire = function(event)
if event.phase == “ended” then
bullet = display.newImageRect(“bullet.png”, 5, 30)
bullet.x = player.x + 50
bullet.y = player.y
bullet.myName = “bullet”
transition.to (bullet, {time = 500, x=400, onComplete =function()bullet:removeSelf();bullet=nil;end })
physics.addBody (bullet, {density = 0.1 })
localGroup:insert(bullet)
bullets = bullets - 1
print(“Shot bullet”)
local destroyPowerup1 = function()
if bullets == 0 then
firebutton.isVisible = false
powerup1 = false
end
end
destroyPowerup1()
end
end
firebutton:addEventListener(“touch”, fire)
end [import]uid: 114389 topic_id: 31811 reply_id: 331811[/import]
[import]uid: 114389 topic_id: 31811 reply_id: 127043[/import]