Save global variables (score) in an array

0 favourites
  • 10 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hey there,

    I use some global varibles for my score. I wanna save all my global variables in account of the score into an array at the end of my level and load it on level starts.

    So if i quit the game and start it new, it should load the value storing in the array.

    Can anyone help me?

    I want to save all my global variables into an array. And i also want to save the array with the webstorage function. But i don't know exactly how I tried the Load/Save function but this causes issues on CocoonJS.

    Thanks for helping out!

  • Can nobody tell me how i can save my global variables in an array and webstorage?

  • To save the global vars to an array you can set the value for each index in the array, like that:

    Array.SetValue at X (0) = var1;

    Array.SetValue at X (1) = var 2;

    etc.....

    WebStorage only save strings(text), so you can do something like that:

    for(0 , array.length-1)

    Webstorage.SetKey > "key"+loopindex > array[loopindex] //I'm not sure what's the correct action..use the one for saving..I'm on a mac now, can't check it.

  • Thanks for your input. I'll try it as soon as possible

  • You can convert the array to JSON format, which should then be able to be stored in WebStorage as a string without any problem.

    So for the value box of the WebStorage Set Local Value command, you'd just use "[YourArray].asJSON"

    Then when you start up your project you just tell [YourArray] to load up the JSON formatted string from your webstorage.

    So for the load action on [YourArray] you just put in: WebStorage.LocalValue([ChosenKeyName])

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi,

    Thanks. I've already have red about this option. But i don't know how to use it.

    I usea global text variable "game" with three stats.

    • start
    • play
    • finish

    On start of Layout it will be set to "start". Here the game should load the variables stored in the webstorage and array (as far the exist). If the player starts the game with the play button the value will be set to "play". If he dies the value will be set to "finish". Here the game should safe the values of all global variables.

    Do you know how to handle this? I currently use the save and load function but this causes many "problems".

    Thanks a lot!

  • A few weeks ago I have the same problem. I also don't know how to use the webstorage correctly. There is a lack of examples on this

    Anyway, here is my capx were I am able to save and retrieve data from the array.

    Run the capx, click on some buttons and do save, refresh browser, click load. Voila, data is back!

    These are event based, so you can use it for On layout load to do the trick instead of having to push the load button.

    ikkez

  • Thanks ikke2902,

    Great job, but i want to save numbers like scores in an array. Do you also know how to do this??

  • Take a look at this link at the last post https://www.scirra.com/forum/viewtopic.php?f=147&t=98171. Baodingball made a capx for saving scores.

    Hope that helps

  • Thanks

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