How do I get lives/current life to carry over to next level/layout?

0 favourites
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hey everyone, I want to know how to keep the current lives of the player when player beats the level and goes to the next one, like in pacman. When my player wins the level, even if the player has one life left, if he beats the level and goes to the next one, he has full lives again and I don't understand how or why. But I know it might have something to do with my players life variable. For the variable, the player has 2 lives to start with. Im trying to keep it current for all the levels if the player is to have 1 life or 0 lives left, it stays like that for all the levels until that player die or gain a new life. Any suggestions for this?

  • Because in each level you create the player again and he begins with default state and what I assume is instance variable lives. You can use global variable instead for lives which retains its value throughout, this is good for player stats.

  • Two options:

    1. Track the player's lives in a global variable

    2. Make the player object a global object

    If you only need to track a few variables then making them global variables may be best. But if you need to keep track of lots of instance variables, then making the object global may be best.

  • Because in each level you create the player again and he begins with default state and what I assume is instance variable lives.

    Yes I think thats correctly right on. I have the player on every level when you beat it a level. So, by default, it basically set back to the default variable.

    Fib

    Thanks for the options! Thank you both for the help!

  • Thanks Fib, the second option worked! Thanks for your help too lion.

  • Fib

    Uhhh...one more question. Now that I got my lives to correctly carry over to the next layout, how do I get the lives display to as well? Do I just use a global variable to check of the lives display correctly? For some reason, if I have 1 life and go to next level with 1 life left, it shows to 2 lives displayed still. If I die on the next level with 1 life, it corrects the life display to 0. I thought making the object global since I have them on every level as well and they use an ID variable to mark off a life display.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well it's a problem with your events but can't see them. There is no need to use instance variables and global variables for the same thing so don't do that.

  • Hmm okay. Um hopefully this event screenshot might give you something to find wrong of what's not working. The Jet.LivesFam is a family for the lives display. They have a family instance variable called IDFam. This is to give each life display an number ID to assign order and to correctly mark off the life display in the correct order of losing a life or gaining a life.

  • Assuming that all works, this isn't the event to display the lives, let's see that.

  • Uhh, that IS the event to display the lives. there is no "display lives" event of just an event to display lives. The lives are already displayed at the start of the game/layout. the rest of the lives are hidden on start of layout. They are not in the event sheet of the start of layout as invisible or visible. But I will post that to let you see.

  • The jet display 1 and 2 are not in the events in start of layout. They are out when the game starts and are not in events as visible or invisible.

  • And how does jetlivesdisplay object relate to the lives variable?

  • There are 3 ways my player can die, either by wall damage, bullet collision and enemy collision. If the player gets killed in either of these ways my event will take subtract 1 from the "Game" object I made global that fixed the lives to carry over to a new level. My jetLivesDisplay are linked to it in the event I shared. But only event wise.

  • The JetLivesDisplay IS the object and name of the object. Where its highlighted in the photo, They are in a family called "JetLivesFam". JetLivesFam has instance variable called "IDFam" for the JetlivesDisplay object. In the event, it connects to the "Game" object that is an global object, and do global object "Game" holds the lives of Player1 in an instance varible called "LiveP1" as you see in the highlighted circled events and actions.

  • This is the "JetliveDisplay" object. and the name of it is "JetLiveDisplay".

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)