How do I reset just only a global variable.

Get help using Construct 2

Post » Sun Mar 15, 2015 6:16 pm

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.
B
10
S
3
Posts: 271
Reputation: 1,358

Post » Sun Mar 15, 2015 8:27 pm

Instead of reset, use "set" variable and set it to the initial value.
Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

Post » Mon Mar 16, 2015 5:40 am

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:
Code: Select all
constant INIT_TIMER = 20;
var Timer = 0;
<...>
Timer = INIT_TIMER; //reseting your value to initial


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.
B
8
S
1
Posts: 72
Reputation: 606

Post » Mon Mar 16, 2015 2:55 pm

@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.
B
10
S
3
Posts: 271
Reputation: 1,358

Post » Mon Mar 16, 2015 5:36 pm

@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...
B
10
S
3
Posts: 271
Reputation: 1,358

Post » Mon Mar 16, 2015 6:04 pm

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.
Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

Post » Mon Mar 16, 2015 7:37 pm

@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.
B
10
S
3
Posts: 271
Reputation: 1,358

Post » Mon Mar 16, 2015 8:02 pm

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
Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

Post » Tue Mar 17, 2015 4:19 pm

@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.
B
10
S
3
Posts: 271
Reputation: 1,358

Post » Tue Mar 17, 2015 4:38 pm

Message: Radulepy can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
@frostyelk
No more, i did it...
Thanks a lot, without you couldn't succed, i found here a nice .capx
viewtopic.php?f=148&t=64347&p=898110#p898110
B
10
S
3
Posts: 271
Reputation: 1,358


Return to How do I....?

Who is online

Users browsing this forum: mercuryus, Moordhuis, RetroSpock, TRMG and 9 guests