Using local storage for level progress.

0 favourites
  • 7 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • Just wondering if I am doing this right.

    I have 10 maps (each map is a whole game). Once you complete a map, I want to set it as completed. I then bring the player back to the map selection area and I want to update the visuals showing them having completed a map.

    Do I create Local Storage key for each map? 0 is not yet complete, 1 is complete?

    I was going to load an array[10] and have the 0/1 value for each one. Then base on the 0/1 with a graphic whether the map is complete or not.

    Since I have to check if each key exists first, should I just create all the keys on the first ever play? then load the key data from there? Should I load the keys on the mainmenu rather than level select, just so the data is ready?

    also can I save a whole array to the local storage in one move or do I have to make "map1", "map2" etc.. keys?

  • You can save the array data in JSON format as one key. During the game update the array accordingly as levels are completed and save into local storage each time it's updated. When you launch the app you can load the array from local storage and check against it for level completion.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • something like this?

  • Not sure what the idea is behind those events. You set item to array.asjson whenever you need to save, if that's only on start of layout then that's fine. To get the array you should be doing this on start of layout I guess right at the start of the game.

  • Hey jobel, I was curious about how to do this as well, and took a shot at it. See if this project file is useful for you!

    drive.google.com/file/d/1iGHAfTcqPZI1DBLR9wVgsc3_lqIW-mwX/view

    EDIT: Click on the squares to set the "level" to complete/incomplete. Then you can click save, reload the preview, and see that the complete levels are saved.

  • something like this?

    Make sure you use "on item set" when you set an item before you try to get it again as Local storage takes multiple ticks depends how big is the data so you may "call get Item" like in your trigger once before the item is set.

    And alternative you can use the wait for previous Actions

    -Local store set Item "Name"

    -Wait for previous Actions to finish

    -Local storage get item "Name"

    Assuming that yo just testing for now as normally you set the item just once then you just have to use "Get item" alone until you delete the key.

  • thanks all, yeah I was just wondering if it was valid to write the whole JSON to the item and then vice versa for the 'get'. I couldn't tell for sure if that was okay. but its way easier to do that and make a whole array database structure rather than save individual items! thanks again!

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