Stop instant variables resetting?

Get help using Construct 2

Post » Thu Jan 21, 2016 2:27 am

is there a way to stop instant variables from resetting when the layout is reset? I have 22 separate objects and each works independently. So I don't want to make 22 global variables if i can make it so that the instant variables don't reset.

Thank you
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Thu Jan 21, 2016 2:59 am

Put them into an array, then make themselves load from the array after reset?
B
47
S
14
G
4
Posts: 177
Reputation: 5,389

Post » Thu Jan 21, 2016 3:06 am

Callan S wrote: Put them into an array, then make themselves load from the array after reset?


Great thank you. Is there a way to attach this array to a web storage so that when the game is reloaded it will keep the data? can it all fit into a single webstorage?
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Thu Jan 21, 2016 3:23 am

You can save the array data with Array.AsJSON, then Array.Load to get it back.
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Post » Thu Jan 21, 2016 3:33 am

blackhornet wrote:You can save the array data with Array.AsJSON, then Array.Load to get it back.


Thanks a lot. So this will save the data even when the app is closed? Does the same job as Web storage?
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Thu Jan 21, 2016 3:51 am

No, you use Web Storage to save the string from AsJSON, and then again to load the string.
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Post » Thu Jan 21, 2016 9:49 pm

@blackhornet So I would start of by doing the following/

On start of layout > Push "object a" on X axis
Push "object b" on X axis
Push "object c" on X axis..........etc

Then that associates the objects with the array right?

Then what do I do?
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Thu Jan 21, 2016 10:31 pm

No you can't put objects in the array only data. What data are you trying to store?
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Post » Fri Jan 22, 2016 2:13 am

@blackhornet Okay it may be a bit complex to explain but here goes......

I have a game where you collect gems using a player. These gems can then be used to buy different characters. If you can afford the character then it is highlighted in black and white so you can see the character, but you're not able to click on it (only the coloured ones work when clicked on). If you have enough money/gems then the player is in colour and therefore available to purchase.

I used an instant variable (called 'upgrade') in each character for the following purpose. when the person click on a coloured character (one that is available for purchase) 1 is added to the instant variable. If the instant variable is 1 then the player REMAINS in colour. Without this instant variable after restarting the game and going back into the upgrade shop the payer is no longer highlighted since you dont have enough money unless the variable is 1.

So i want to make a webstorage that will remember the instant variable for when the person closes the app and opens it again.

I hope this made sense :) thank you
B
8
S
2
Posts: 146
Reputation: 1,132

Post » Fri Jan 22, 2016 2:58 am

One way is to create an array with a width of 22 (from your first post) and give each of your characters an index variable. Use that index variable to index into the array. Do your calculations in the array at that character's index. When you shutdown, save the array. When you start up, read the array.
ImageImageImage
B
71
S
19
G
180
Posts: 3,482
Reputation: 103,185

Next

Return to How do I....?

Who is online

Users browsing this forum: AmpedRobot, katito13, oosyrag, RetroSpock, senna68, yme and 6 guests