I want to reset my layout but without resetting the Global Variable.

0 favourites
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Greeting Construct 2 users,

    In my game, the player have 3 chances (lives). When the player loses the game, 1 chance is subtracted from the text object named "txtChances", then a box appears on the screen with a "Restart" button to restart the level. If the player clicks "Restart" the layout will restart. But unfortunately, when the player clicks the restart button, the Global variable that controls the number of chances that the player has will also restart and the player will regain his 3 chances every time that he or she loses. How can I make the number of chances decrease each time that the player loses without resetting the value of the Global variable when the player click the restart button to restart the level?

  • Restarting the layout does not reset the global variables so you must have another event doing it.

  • To plinkie:

    I give the initial value of 3 when the player loses the value drop to 2. When the player clicks the reset button the value comes back to 3 again. So yes resetting the layout resets the variable.

  • Restarting the layout doesn't reset the global variables back to their initial values, they stay the same.

    Let's see the file

  • To plinkie:

    Can I send you a screenshot, rather than sending you the file?

  • A screenshot might be fine if it's all the events but the file is better so I could debug it straight away

  • To plinkie:

    Where can I send you the file? At your email address?

  • Use the search in C2 to look for "NumberChances" in your event sheet and take a screenshot of that, maybe that'll work. Or, maybe you have an event that uses "Reset global variables to default".

    As plinkie said, global variables extend to the entire project, so resetting one layout should not reset them.

  • Well I'm on discord if you want ant#4434

  • To plinkie:

    I can't send a screenshot anymore the forum seems to refuse that people post images. Can you tell how can I send you the .capx file of my game?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To plinkie:

    I can't send a screenshot anymore the forum seems to refuse that people post images. Can you tell how can I send you the .capx file of my game?

    Images can be posted, but you have to post first without image, then edit your post and add your image.

  • To plinkie:

    This is the Event Sheet related to the Global Variable named "NumberChances". In this Event Sheet, you will see all the conditions and actions related to the "NumberChance" variable. I hope that this will be enough for you to find why the value of the "NumberChances" variable comes back to 3 when the player presses the reset button. If you can't find the solution tell me how I can send you the .capx file of my game. :

  • There's probably some missing events. You can upload to dropbox and post the link here, or add me on discord ant#4434

  • To plinkie:

    Heres a dropbox link to my .capx file: dropbox.com/s/3xg9c9exydkxrwd/Triple%20Shape%20Code-au9cgh88s937.capx

  • The variable is correct but the text displayed is wrong. Make sure you are updating the text after the variable updates. I saw my chances were 1 but the text object is showing 3.

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