How do I use Array with LocalStorage

  • I've 50 buttons, each one for a specific level. Ath the beggining of the game, these buttons are set with 50% of opacity and they are disable. When the player finishs the level, if he/she wins, the button's opacity changes to 100% and its frame to different one that show a specific badge, in according with a variable that store the points. Before to use badges, I was using local storage to store the "lock/unlock" variable. But with the badges (3 in total) I know that I need to use an array. The problem is that I never used an array with local storage. Can someone help me with this issue? Thanks in advance.

  • You can use the Array object's AsJSON expression to get the contents of the array as a JSON string, which you can then put into local storage. When loading, use the Array object's Load action to load the array from the stored JSON string.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use the Array object's AsJSON expression to get the contents of the array as a JSON string, which you can then put into local storage. When loading, use the Array object's Load action to load the array from the stored JSON string.

    I don't know much of arrays and Json. I don't imagine how to prepare the array for this situation and how to save the informations of the each button in the arrays and in the local storage after and how to load and show the right buttons frames. I need more detailed informations, if is possible, but, thanks anyway.

  • There are multiple tutorials on how to use arrays and many examples in the forum..

    The saving part is done as described above..

  • linkman2004

    I create the key and set it to array.asJson. Now, I'm trying to use Localstorage.itemValue("array_key") do load Json and I can't. Do you know where is the problem? Thanks in advance.

  • Without seeing your events I can only guess..

  • LittleStain is right -- you'll need to post either a screenshot of your events, or a link to your CAPX.

  • linkman2004

    I create the key and set it to array.asJson. Now, I'm trying to use Localstorage.itemValue("array_key") do load Json and I can't. Do you know where is the problem? Thanks in advance.

    It's a shame this never got answered.

    I too am wondering what JSON string I need to tell the array to load. The only thing I can enter is 'LocalStorage.Key' but it will not let me specify which key.

  • Answers :

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