How do I Save Location in LocalStorage

  • Hey all, i try to save the Location of Levelselect into Localstorage... But it doesnt work. I will save the unlocked level into Localstorage. If the player restart the game, the latest unlocked levels should appear.

    Hope u know what i mean

    My Code:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The first action, on start - it needs separating.

    Essentially, everything from local storage is brought in 'blobs' - every time you retrieve anything, it has to check the blob, then fetch that blob first - which is two whole interactions, each of which take (a very small amount of) time. So when you use 'Check item exists' you have to use another action to call when the blob check has finished (otherwise it will try and do it in the same tick - which won't work, because the blob hasn't been... blobbed (?) yet).

    The action you need is 'On item exists [CurLocation]' - then use 'Get item [CurLocation]' action in that event. Then you need another event 'On get item [CurLocation]', in which you can FINALLY set the variable! Seems crazy I know.

  • Ok now i have this:

    but it doesnt work... everytime if start the game and unlock the next level it doenst save. On any restart the levels are resetet =( any idea?

  • You aren't setting the CurLocation variable. You don't need event 3. In event 2 replace the 'Get item' with CurLocation = LocalStorage.ItemValue.

    You should add 'On item missing', and set CurLocation = 1, and remove event 7.

    LocalStorage takes time to read. You shouldn't really do anything that relies on CurLocation until either 'exists' or 'missing' is triggered.

  • Doesnt work for me:

    The Tutorial i have done is:

  • On start - check item exists

    On item exists - get item

    On get item - set variable to localstorage.itemvalue

  • Thank you. But where is the current location stored? It must be stored somewhere the current levels so that they are there again when restart

    My Code Now:

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