Is it my solution that dosent work on level 3 or is it the game in general? You have alot of Runtime EventListeners, are you sure that you dispose of them when you clear a played level? Maybe thats the problem. [import]uid: 126729 topic_id: 30306 reply_id: 123701[/import]
Well I hate to say it’s your code. Probably more along the lines of the way I implemented your code. What happens is when all darts are fired on the second level when the third level loads the game is stuck in the gameState function. So instead of doing more waiting time when the third dart is thrown it automatically calls game over. This is what I did with your code to get it to work to this point I may have jacked something up. I stopped calling the lost function as a listener and I just call the function when the events for losing occur.
[lua]-- inside the update function
if dartsLeft == 0 and balloons.numChildren ~= 0 then
print(“first if”)
if (lastDartThrown == false) then – This to stop multiple timers from starting
print(“second if”)
lastDartThrown = true
timer.performWithDelay(17500, checkGameState) – After 2,5 sec or the timeframe from dart is thrown until the balloon should have been hit.
end
end
—gameState methods
local function lost()
if gameState == “over” then
if dartsLeft == 0 and balloons.numChildren ~= 0 then
gameLosing()
Runtime:removeEventListener(“enterFrame”, lost)
end
end
end
local function checkGameState()
if balloons.numChildren ~= 0 then
print(“third if”)
gameState = “over”
lost()
elseif balloons.numChildren == 0 then
lastDartThrown = false
print(“fourth if”)
return
elseif table.maxn(levels) == currentLevel and balloons.numChildren == 0 then
print(“won”)
end
end [import]uid: 49863 topic_id: 30306 reply_id: 124205[/import]
Actually I just added return true instead of return and that seems to have fixed it. It will take some Q & A time but I think this fixed it. [import]uid: 49863 topic_id: 30306 reply_id: 124221[/import]
Well I hate to say it’s your code. Probably more along the lines of the way I implemented your code. What happens is when all darts are fired on the second level when the third level loads the game is stuck in the gameState function. So instead of doing more waiting time when the third dart is thrown it automatically calls game over. This is what I did with your code to get it to work to this point I may have jacked something up. I stopped calling the lost function as a listener and I just call the function when the events for losing occur.
[lua]-- inside the update function
if dartsLeft == 0 and balloons.numChildren ~= 0 then
print(“first if”)
if (lastDartThrown == false) then – This to stop multiple timers from starting
print(“second if”)
lastDartThrown = true
timer.performWithDelay(17500, checkGameState) – After 2,5 sec or the timeframe from dart is thrown until the balloon should have been hit.
end
end
—gameState methods
local function lost()
if gameState == “over” then
if dartsLeft == 0 and balloons.numChildren ~= 0 then
gameLosing()
Runtime:removeEventListener(“enterFrame”, lost)
end
end
end
local function checkGameState()
if balloons.numChildren ~= 0 then
print(“third if”)
gameState = “over”
lost()
elseif balloons.numChildren == 0 then
lastDartThrown = false
print(“fourth if”)
return
elseif table.maxn(levels) == currentLevel and balloons.numChildren == 0 then
print(“won”)
end
end [import]uid: 49863 topic_id: 30306 reply_id: 124205[/import]
Actually I just added return true instead of return and that seems to have fixed it. It will take some Q & A time but I think this fixed it. [import]uid: 49863 topic_id: 30306 reply_id: 124221[/import]