Keep Score between layouts

Get help using Construct 2

Post » Thu Nov 21, 2013 10:46 am

Did you read my last post?

I'm talking about adding an instance variable to a global object or setting the value in a global array and retrieving it after resetting the global variables.
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 » Thu Nov 21, 2013 10:51 am

for the webstorage part,instead of set key in the start of layout you should do something like:

system set value score to webstorage.localvalue("score")
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 » Thu Nov 21, 2013 11:25 am

Yes I see thanks

Will try to get this webstorage to work
Must be doing something wrong in that

My global is Score
and my textobject is txtScore

the sprite PlayBtn > Set local key "txtScore" to Score
( this should save the value am I right )

in next layout 2 I have made a button to get the score for testing

Button Is checked > system set value score to webstorage.localvalue("Score")
B
33
S
17
G
11
Posts: 350
Reputation: 8,695

Post » Thu Nov 21, 2013 11:49 am

I had this issue too. I did pretty much like you did, but instead of using webstorage, I used a dictionary. Then I created a function called resetGlobals(), in which I first copy the variables I want to keep into the dictionary, then reset the global variables, and finally copy back the values from the dictionary to the global variables. Then I just call this function whenever I need it, like when changing layout.
Having everything in one function is easier to maintain, especially if you want to add more variables later (score, sound volume, language...)OlivierC2013-11-21 11:51:48
B
12
S
5
G
2
Posts: 132
Reputation: 2,637

Post » Thu Nov 21, 2013 12:04 pm

Well now .. got it working!

Forgot System Set Score to Score
before
WebStorage Set lokal key "Score" to Score


Thanks 4 replies :-)flemmig2013-11-21 12:05:21
B
33
S
17
G
11
Posts: 350
Reputation: 8,695

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests