Reset global variables (except one)

0 favourites
  • 8 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.
  • I'm implementing a load/save feature and the way I want to do it, is to restart the layout (which resets everything, destroys excess objects etc) and then reload the saved position over the top of the newly created objects. This will give me a nice clean reload.

    The problem is, to restart the layout cleanly, I also want to reset the global variables. Then when a new game is restarted, it will check a variable to see if the player is restarting from scratch, or restarting from a reload. If reload, it will then pop to the reload function.

    The problem is, where can I store the variable, because if I'm resetting all globals, that will also reset my 'Reload' variable which tells it to do the reload.

    The alternative of course is to just refresh the variables in code at start-up, but it's a bit long-winded if there's a simpler solution.

    So in short, is there somewhere else I can store a variable which will survive a 'Reset all globals' command?

  • Yep you can store it in session storage.

    WebStorage: Set session key...

  • Ah of course, good idea. I was thinking of webstorage but was thinking it would be bad to store something so temporary, but since it's only session storage, that's 'throw-away' storage anyway. Thanks.

  • I am currently storing mine in a dictionary as I have a lot of values, but there are a lots of "set" and "get" expressions flying around, but it works best for me. Lets me recycle lots of values and it keeps them global.

  • Damn I wish I knew what you were talking about. But I'll get there.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try this:

    1. create a group and add a local variable..

    2. set the local variable value to the global variable value that you want to preserve..

    3. reset all global variables..

    4. set back the global variable value to the local variable value..

    Good Luck

  • Save that variable in a dictionary. I have about 70 'global' different variables in one of my projects, but 50 of them are stored in a dictionary I call 'global'.

    On the start of the layout, add an event:

    global -> add key "call_restart_function" with value 0

    and also

    If global.get("call_restart_function") = 1 -> call "restart" function

    Then when they restart, add an event:

    global -> set key "call_restart_function" with value 1

  • Very Easy: use Behavior "PERSIST".

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