Stop instant variables resetting?

0 favourites
  • 11 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • 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

  • Put them into an array, then make themselves load from the array after reset?

  • 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?

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

  • 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?

  • No, you use Web Storage to save the string from AsJSON, and then again to load the string.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

  • No you can't put objects in the array only data. What data are you trying to store?

  • 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

  • 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.

  • blackhornet Thank you I'll give it a go and let you know

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)