Saving and Loading an Array

1 favourites
  • 4 posts
From the Asset Store
Match the similar cards with each other and free all animals!
  • I figured out how to save and load my sound settings. Apparently Saving and Loading an Array is not quite as easy.

    Based on what I have read from the array info and the local storage info I have the following.

    I first check if "ArraySave" exists

    If it is missing I Set Item "ArraySave" to Levels.AsJSON

    Levels is the name of my Array

    If it exists, then I have local store get item "ArraySave'

    Then I have it my Array called Levels Load from JSON String "ArraySave"

    I saw somewhere you can use AJAX to do it, but the steps say to retrieve array and I dont have that option. I can retrieve a project file or a URL.

    I appreciate any help.

    Tagged:

  • Check if "ArraySave" exists
    
    On "ArraySave" exists : Levels load from LocalStorage.ItemValue
    

    Check out this demo:

    howtoconstructdemos.com/easily-save-multiple-values-in-local-storage

    It's using a dictionary, but you can use the same method for saving/loading an array.

  • When I click the link it takes me to the demo editor. I downloaded the demo but the cp3 is using functions I am not familiar with. Based on what I have read I should be able to use a Load from LocalStorage.ItemValue but I want to make sure that it is picking up the array and not my sound settings.

    On a side note, I have tried using AJAX as this seems pretty simple, but it won't let me pick my array. When I call project file the only things I have in the dropdown are some icons. It wont let me manually type the name of my array or select it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I suggest you read about functions, they are really useful.

    You don't need AJAX if you are working with Local Storage.

    If you need to save two arrays, you give them different item names. Then you check if "SettingsArray" exists and if "LevelsArray" exists. And you should have two "On item exists" events:

    On item "SettingsArray" exists : SettingsArray load from LocalStorage.ItemValue

    On item "LevelsArray" exists : LevelsArray load from LocalStorage.ItemValue

    That's it.

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