game over screen

currently i want to track when the score goes < 1 and then bring up the game over scene.

just wondering how to check the score value after losing health and bring up the game over screen if health is less then 1. i have it down with the following code but it only works once i enter the room and not updated after the health is reduced. i know there was to be a way to do this in one function.

heres what i have
code from start of code

local function lose25Health( self, event )  
 if event.phase == "began" then  
 \_G.playerHealth = \_G.playerHealth - 25  
 storyboard.settings.playerHealth = \_G.playerHealth  
 storyboard.saveTable(storyboard.settings, "settings.json")  
 \_G.playerHealthText.text = \_G.playerHealth  
 print ("loss - 25: now is", \_G.playerHealth )  
 print ("")  
 return true  
 end  
end  

and here is the code from the enter scene part

if storyboard.settings.playerHealth \< 1 then print ("Life is BELOW 0") else print ("Life is Above 0") end [import]uid: 17701 topic_id: 27393 reply_id: 327393[/import]

Well i would give two recommendations, one would be to make a runtime listener that would watch the players health and activate game over if the player is below 1 health or you can create a function that you call everything the player looses health. For example:

[lua]–Option one Create a runtime listener
local function checkHealth ()
if storyboard.settings.playerHea;th < 1 then
print (“player is dead”)
end
end
Runtime: addEventListener(“enterFrame”, checkHealth)
–That will check the health of the player to see if its below 0 for every frame.

–Option two call the function when the player looses health.
local function checkHealth ()
if storyboard.settings.playerHealth < 1 then
print (“player is dead”)
end
end

local function damagePlayer ()

if player.isHit == true then
storyboard.settings.playerHealth = storyboard.settings.playerHealth - 25
checkHealth()
end
end[/lua]

The above two are just a couple of ideas for how to handle game over. Also within the checkHealth function you can bring up your game over screen if the player is dead. And i recommend putting in a gameover/pause boolean that you can use to stop all action in game. [import]uid: 126161 topic_id: 27393 reply_id: 111299[/import]

3 Dreams Gaming,

thanks for the two suggestions, I’m going to give it a try tomorrow and hopefully it works for me.

thats probably what i was doing wrong i didn’t have a runtime listener.

in line 7 its using the “enterFrame” in the event listener,

Runtime: addEventListener("enterFrame", checkHealth)  

im not sure what the enterFrame is referring to, i looked on this site, but I’m not given information regarding it.

thanks [import]uid: 17701 topic_id: 27393 reply_id: 111456[/import]

“enterFrame” will run the function once every frame. It is pretty much a function loop that wont stop until the user exits the app or you stop the “enterFrame” event with removeEventListener [import]uid: 126161 topic_id: 27393 reply_id: 111480[/import]

3 Dreams Gaming,

i got it working with the second method you posted, as i wanted it to happen when the loss health event begins.

thanks [import]uid: 17701 topic_id: 27393 reply_id: 111523[/import]