Keep variable values

Get help using Construct 2

Post » Thu Jan 17, 2013 12:46 am

Hi,

I'd like to know how to keep the variable values the same, even as I change layouts. Currently, when I change layout, the global variables will reset, but I'd like them to stay at their current value, in order for me to present the user with their score at the end.

Thank you

-Frodo.FrodoBaggins2013-01-17 00:47:10
B
4
S
1
Posts: 20
Reputation: 790

Post » Thu Jan 17, 2013 12:53 am

Use the Webstorage ! It's the best way to keep your data secure ! ( Sounds like an anti-virus add , does it :D )

Just save your variables to a local key and re-load them back when switching layouts !

Don't forget to contact me if you need any help ! Just type @Whiteclaws in your posts and I'll fly to help you :D

Cheers !
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Thu Jan 17, 2013 9:06 pm

Thanks Whiteclaws!

lol indeed it does - but I'm still a bit stuck.
The score indicator works, but only on a page refresh. So if I finish the game, the score indicator will indicate 0, then once i've refreshed the page, it will go to its proper value

Any ideas here?

ThanksFrodoBaggins2013-01-17 21:07:13
B
4
S
1
Posts: 20
Reputation: 790

Post » Fri Jan 18, 2013 10:07 pm

Bump
B
4
S
1
Posts: 20
Reputation: 790

Post » Fri Jan 18, 2013 10:39 pm

You can always contact me with @Whiteclaws in your posts

You need to also save your score value in a global variable at the end of the game ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Sat Jan 19, 2013 4:14 am

@Whiteclaws the variable is incremented each time the user scores a point, then at the end of the game it is written to the Session webstorage variable. The problem i'm having is that the label shows 0 on the scoreboard, it will only show the correct value after refreshing.
B
4
S
1
Posts: 20
Reputation: 790

Post » Sat Jan 19, 2013 4:49 am

Post your capx, it will make it easier for us to tell you exactly how to do things correctly.

You may also want to consult tutorials like Asteroid clone in less than 100 events that will show you some usage of global variables, several layouts as well as some webstorage.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jan 19, 2013 5:03 pm

Are you sure you are changing the text each time the variable changes ?
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Sat Jan 19, 2013 5:04 pm

Every Tick | Set Text to (Variable)
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Sat Jan 19, 2013 5:50 pm

[QUOTE=FrodoBaggins] Hi,
Currently, when I change layout, the global variables will reset[/QUOTE]

Unless you are triggering the "Reset global variables" action, they shouldn't be. That's the whole purpose of global variables.

Global Variable Demo Capx
R115: Press space bar to progress to the next level. Notice how the score does not reset.

Be sure you don't have any "On start of layout" events where you are setting the score back to 0 - this will fire every time you change to a new layout, not just the first time you start your game. boolean2013-01-19 17:52:14
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Next

Return to How do I....?

Who is online

Users browsing this forum: Rezzon71, theosciandra and 23 guests