How do I reset just only a global variable.

0 favourites
  • 10 posts
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.
  • Ok,

    so I'm working on a game and if a global variable (Timer) is less than e.x 20 you get 3 starts

    and I would want at the end of game to reset this variable, but just this becouse when you gain a star, or 2 or 3 than it counts them and tells you in the Menu.

    So in conclusion how to I save a variable and reset another when you fail (restart) the level?

    Thanks, I'm not sure how to do this.

  • Instead of reset, use "set" variable and set it to the initial value.

  • frostyelk is right!

    another advice will be to make a Constant to store this initial value.

    it will save you later from remembering when you store what value and probably from logic mistakes.

    Example:

    constant INIT_TIMER = 20;
    var Timer = 0;
    <...>
    Timer = INIT_TIMER; //reseting your value to initial
    [/code:19hndrk4]
    
    now you need just to change INIT_TIMER at the top of your event sheet.
    very useful if you use this reset in several parts of your game.
    or you will need to search and change values in all this places.
  • NickRimer, frostyelk

    Thank you very much, but I think I will use the first one becouse is more simple.

    Didn't think to "set variable", thank you again for the idea.

  • NickRimer frostyelk

    I made it but I have an other question.

    I save the variables but, when i quit the game and enter again it shows me that i have 0 starts and if i press play and go back to menu it shows them again.

    How can i make that it saves the variable, but just it becouse i put on start of the layout load"mysave"... but it gets me to the game and not to the menu.

    Thank you, i know it sounds bad...

  • Not really sure i understand your problem.

    I am guessing that you want the player to get new lives after X amount of time?

    In order to do this you need to know what time the player started to play the game, and what time the player stopped playing the game.

    You then need to check if X time has passed since the player played last time. Best way to do this is to use real time, i have used UnixTimeStamp for this and saved it in a variable.

  • frostyelk

    No, ok so If it starts the game it should load the saved variables but not the game (shouldm't start the game, just load the variables without starting the game)

    Thanks for all, you're the best.

  • The problem with Save´s is that they save everything and remembers where you where exactly when the SAVE was made.

    So you need to use WebStorage instead of saves and just save the variables you need and not everything.

    https://www.scirra.com/manual/120/webstorage

  • frostyelk

    I don't know exactly how to do that becouse it doesn't loads it on start of the layout could you please, if you have time, make me a small example of saving a variable and on game start to automatically load it?

    Thanks a lot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • frostyelk

    No more, i did it...

    Thanks a lot, without you couldn't succed, i found here a nice .capx

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