0 Favourites

How do I save and load game settings?

  • I stored the game settings on an array, now i wish to know how can i save this data in a local storage and retrieve this data when the game restart? Also how can i to populate the settings with the retrieved data?

    It is just 7 settings that can be changed by the user, so i've used an array (6,1,1).

    I used

    local storage -- set items "Settings" to array.AsJSON (to save the data)

    and

    On item "Settings" exists -- array load from JSON string "Settings" (to load the data)

    but it is not working...what i'm missing?

    Thanks!

  • Hi,

    You have to perform a "Check item exists" before the "On item exists will be triggered.

    So add an aciton on the start of the layout "Check "Settings" exists".

    If so, it will be loaded from the LocalStorage, if not, then not.

    Regards

  • AndreasR,

    Thank you!

    I've added the "Check item exist" before the "On item exist..." but it still not working. Using the debug i can see the local storage with the correct values stored, even if i restart the game without changing anything, but i can't use the values for some odd reason that i don't understand. The array still empty, when it is supposed to be filled with the values. But the fact the array is empty, is just a clue that something isn't working. I've tried to get the values directly from the local storage, without worrying to fill the array with them, like this:

    Music volume(slider) -- set value to int(local storage.KeyAt(3)) [3 is the position where the value is stored]

    but this also not working. It always give me "0" even if the localstorage shows me the correct value.

    I really don't know what to do now...

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • >On item "Settings" exists -- array load from JSON string "Settings" (to load the data)

    but it is not working...what i'm missing?

    On item "settings" get.....Array load from JSON string LocalStorage.ItemValue

    sliders.capx

  • Korbaach,

    Thank you very much!

    One day I would like to have this ability to understand the C2. Awsome work!

    Regards!

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