I have no clue what I'm doing wrong! >:(

I’m having a problem destroying my powerup. I looked at 2 previous forum posts with the same problem but I still couldn’t get it to work. I tried putting the destroyPowerup1 function outside of the powerup1 function but still couldn’t get anything to work. Can someone tell me what I’m doing wrong? I also tried initiating the powerup if you’ve collected the “bill” 10 times but couldn’t get it to work, so I just went with initiating it after 1 collision. I have no clue what I’m doing wrong >:(

[code]

– This object initiates the power-up –

function moneySpawn()
bill = display.newImage(“100.png”)
bill.x = 510
bill.y = math.random( 0, 280)
localGroup:insert(bill)
transition.to (bill, {time = 1500, x = -50 })
physics.addBody ( bill, {bounce = 0.6})
bill.angularVelocity = math.random( -200, 200 )
bill.myName = “bill”
bill.collision = billCollision
bill:addEventListener(“collision”, bill)
end

function billCollision ( self, event )
if event.phase == “began” then
if self.myName == “bill” then
if event.other.myName == “player” then
money = money + 100
moneyText.text = tostring(money)
powerup1()
self:removeSelf()
elseif event.other.myName == “leftwall” then
self:removeSelf()
end
end
end
end
timer17= timer.performWithDelay(30000, moneySpawn, 0 )

– Power-up function –
money = 0
powerup1 = false
powerup2 = false
local powerup1 = function()

powerup1 = true
timer.pause(timer17)

local bullets = 15

local firebutton = display.newImage(“firebutton.png”)
firebutton.x = 420
firebutton.y = 255
firebutton.isVisible = true
localGroup:insert(firebutton)

local fire = function(event)
if event.phase == “ended” then
bullet = display.newImage(“bullet.png”)
bullet.x = player.x + 30
bullet.y = player.y
bullet.myName = “bullet”
transition.to (bullet, {time = 1000, x=550, })
physics.addBody (bullet, {bounce = 0.6, radius = 10 })
localGroup:insert(bullet)
bullets = bullets - 1
print(“Shot bullet”)

local destroyPowerup1 = function()
if bullets == 0 then
firebutton.isVisible = false
timer.resume(timer17)
powerup1 = false
end
end

end
end
firebutton:addEventListener(“touch”, fire)
end [import]uid: 114389 topic_id: 28622 reply_id: 328622[/import]

Well I see one real problem and what will very likely be a problem when you fix the first one.

Where do you ever call the function “destroyPowerup1()”???

The 2nd issue is that function is scoped to only be available inside the surrounding if statement and can’t be called from where where but inside that if statement.

I suspect though that if you just removed the “local destroyPowerup1 = function()” line and it’s corresponding end, you might get the effect you’re looking for.
[import]uid: 19626 topic_id: 28622 reply_id: 115413[/import]