How do I keep the global variables after I lose a game?

Get help using Construct 2

Post » Mon Oct 12, 2015 1:17 pm

Hi all,

I am having a weird problem with a game I'm trying to develop. I would like to display the coins earned, games played, and the highest level achieved by the player in the menu screen (using local storage) . However for some reason, the values seem to be getting lost (all values (global variables) are reset to zero) after I lose a game. What is the best way to solve this issue?

https://www.dropbox.com/s/3o4qsm7t7dljzuk/extreme_unstacker%20-%20db.capx?dl=0
B
5
S
1
Posts: 36
Reputation: 451

Post » Mon Oct 12, 2015 1:46 pm

Save the data, using localstorage.

Create a local key, and upon start of the game, load that key into the global variable for coins and such. :)
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Mon Oct 12, 2015 2:14 pm

I guess you'd like to check if current points are higher than the localstorage value, if not set global variable to localstorage.itemvalue, if so set the localstorage to the global variable..

Right now you are only setting the localstorage if it doesn't exist yet..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 12, 2015 3:57 pm

@LittleStain - yes that is the idea. Check if the values in the local storage as less than the global variables, and if so update the local storage to the global variable. How do I go about doing that pls?

@yodason45 - I think I got to that part. :)
B
5
S
1
Posts: 36
Reputation: 451

Post » Tue Oct 13, 2015 10:39 am

Managed to solve it - my method was to save at the end of the game layout (on end of layout - save as 'game'). Then load the values in the menu screen.
B
5
S
1
Posts: 36
Reputation: 451


Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 26 guests