keep value of global variable after moving to another layout

Get help using Construct 2

Post » Wed Nov 30, 2016 6:53 pm

I have a global variable (level) which is increased by one if the global variable (win) equal 1, so that after the player win he can go to the level selection layout and find level 2 opened,

and what I need is to make the global variable (level) keep the value 1 when I go to another layout

it worked fine with me, the global variable (level) kept its value when I used the action go to layout_level_selection inside the win = 1 condition like this:

Image


but when I added the action go to layout_level_selection inside inside a button which will show when the player wins, the global variable (level) value reset to zero, like this:

Image
B
4
Posts: 20
Reputation: 240

Post » Wed Nov 30, 2016 7:01 pm

This won't do what you want anyway. Event 5 will trigger every tick constantly adding 1 to level until a button is pressed. Move your touch events into a Group and in event 5, set win=0, and enable your new group. Disable the group in On start of layout.

This still doesn't explain why level is reset to 0, it should be some large number, due to the tick issue. We'd need to see more to comment further.
ImageImageImage
B
71
S
22
G
248
Posts: 3,759
Reputation: 138,069

Post » Thu Dec 01, 2016 4:56 pm

I saved the global variable (level) using webstorge and load it in the level selection layout and
I realized that value doesn't reset to zero but it increase to 48 instead of 1
B
4
Posts: 20
Reputation: 240

Post » Thu Dec 01, 2016 8:13 pm

Which makes more sense with what I expected. So reread my suggestion on how to fix this.
ImageImageImage
B
71
S
22
G
248
Posts: 3,759
Reputation: 138,069

Post » Fri Dec 02, 2016 1:57 am

Yeah, blackhornet is right, event 5 just keeps running and adding to the level every tick, UNTIL one of those things is touched.

Try making it make win =2, then use a new statement to check if win=2, then if it does, do the touch stuff after that.
B
52
S
15
G
4
Posts: 191
Reputation: 5,612


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 25 guests