guys
quick question
I my game if the player gets hit 3 times I would like to end their life and the game.
How can I do that?
guys
quick question
I my game if the player gets hit 3 times I would like to end their life and the game.
How can I do that?
Define a variable:
local playerLife = 3
Every time the player gets hit:
playerLife = playerLife - 1 if(playerLife \<= 0) then endGame() end
Great i just figured this out last night.based on what you posted i was on track thanks
Not my issue after I restart the game the lives are still seen as only 1 left unless I force the game to relaunch using the simulator.
I am guessing I have to reset the lives in the end game function?
I would put it on start of level/game.
I’m guessing you do the reset by going to another scene and coming back to your game scene. If that’s the situation, you probably need to remove your game scene when the end game scene is loaded. -> https://docs.coronalabs.com/api/library/composer/removeScene.html
If not, can you share the related code with us? Not the whole scene but a sample from it would be enough.
guys I appreciate the responses. I will tinker with the game a bit more. I currently have the lives stated in beginning of game like I said but it only works when relaunch it. It must be something wrong with the start game function.
I will post the code when I get home
I currently have the lives as global variable
lives=5
then I control the lives using if statements similar to what
bgmadclown used in his post but a bit different.
again thanks for the quick response
player life = 3
everytime the player gets hit,
player life -1
if (playerlife <= 0) then
endgame()
player life= 3
end
When you lose the game ends and the players life is set to 3 again and therefore the game restarts
i fixed it but adding the lives variable to the game start(event)
function
Define a variable:
local playerLife = 3
Every time the player gets hit:
playerLife = playerLife - 1 if(playerLife \<= 0) then endGame() end
Great i just figured this out last night.based on what you posted i was on track thanks
Not my issue after I restart the game the lives are still seen as only 1 left unless I force the game to relaunch using the simulator.
I am guessing I have to reset the lives in the end game function?
I would put it on start of level/game.
I’m guessing you do the reset by going to another scene and coming back to your game scene. If that’s the situation, you probably need to remove your game scene when the end game scene is loaded. -> https://docs.coronalabs.com/api/library/composer/removeScene.html
If not, can you share the related code with us? Not the whole scene but a sample from it would be enough.
guys I appreciate the responses. I will tinker with the game a bit more. I currently have the lives stated in beginning of game like I said but it only works when relaunch it. It must be something wrong with the start game function.
I will post the code when I get home
I currently have the lives as global variable
lives=5
then I control the lives using if statements similar to what
bgmadclown used in his post but a bit different.
again thanks for the quick response
player life = 3
everytime the player gets hit,
player life -1
if (playerlife <= 0) then
endgame()
player life= 3
end
When you lose the game ends and the players life is set to 3 again and therefore the game restarts
i fixed it but adding the lives variable to the game start(event)
function