How do I pin two global variable?

Get help using Construct 2

Post » Mon Jun 27, 2016 8:41 am

I have two gloal variables and a button. when i click the button increase "a" variable to 1 and increase "b" variable to 10. every 1 second subtract "b" 1 and every 10 second subtract "a" 1 .
So i click button 4 times then "a"=4 ,"b"=40 . I save this data n localstorage and after 6 second i exit the game . when I' back : "a"= 4 and "b"= 34 . In another word : "b"=34 when i'm back, after 4 second "b"=30 , and then subtract from "a" 1.
or : "a"=6 "b"=60 , 8seconds lef "b"=52, after 2 second should "a"=5.
B
11
S
3
G
3
Posts: 50
Reputation: 2,281

Post » Tue Jun 28, 2016 10:09 pm

The thing is, you never enter the "Every 10 seconds" event (you never stayed 10 full seconds for it to pop), but you do enter the "Every 1 second" event.
To keep data persistent, I'd suggest creating another variable and add 1 to it every 1 second. Then, if it's equals/bigger than 10, subtract 10 from it, and reduce 1 from a.
Save it in the localstorage as well, this should do the trick.
Last edited by trueicecold on Wed Jun 29, 2016 11:27 am, edited 1 time in total.
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Wed Jun 29, 2016 9:40 am

thanks bro.that's cool way :)
B
11
S
3
G
3
Posts: 50
Reputation: 2,281


Return to How do I....?

Who is online

Users browsing this forum: ChoosyZerk and 47 guests