Reset global variables (except one)

Get help using Construct 2

Post » Mon Mar 11, 2013 8:10 pm

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?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Mon Mar 11, 2013 9:07 pm

Yep you can store it in session storage.

WebStorage: Set session key...
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Mar 11, 2013 9:20 pm

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.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Tue Mar 12, 2013 7:08 pm

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.
B
6
S
3
G
1
Posts: 102
Reputation: 1,379

Post » Sat Nov 23, 2013 2:27 am

Damn I wish I knew what you were talking about. But I'll get there.
Check out my latest game RAPID-TAPIT. Get your Fingercise on with this one. A steady Tap is all you need to score points. Lift a finger and see what you can do...

Image

ALLMarkMade Designs
B
23
S
9
G
1
Posts: 326
Reputation: 3,349

Post » Tue Oct 04, 2016 11:26 pm

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 :D
B
4
Posts: 2
Reputation: 204

Post » Wed Oct 05, 2016 1:11 am

Save that variable in a dictionary. :D 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
B
14
S
3
Posts: 17
Reputation: 788


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, makkancs, TiagoCesar and 17 guests