How do I Use Local Storage to Save Game Levels

0 favourites
  • 7 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • Hello everyone,

    I am designing a game with multiple levels, each level on a certain layout. What I want is if a user passed a certain number of levels (e.x passed level 3), I want to load the next level for him when he reopen the game (in our case level 4).

    I tried using localStorage and this is a snapshot of my event sheet:

    d.top4top.net/p_204o9dm1.png

    (to be clear we are now on a home layout (layout 2) which is nothing there just click on the mouse to start playing.)

    what I am doing in this event sheet is I check if the key (levelReched) is not in the storage, if it is not there add it and assign "1" to it.

    in the next event if (levelReached) is there, get it.

    Now if the mouse clicked and (levelReached) value = "1" , got to first level (layout 3).

    and the same for the other levels.

    But the problem is that when I click the mouse nothing happens!! it does not go to any layout, it is still on home layout (layout 2).

    I really appreciate any help from you guys.

  • Haven't used LocalStorage in a bit so maybe I'm not remembering correctly, but, I think you need LocalStorage to run a "check if item exists" (you can stick that into the On Start of Layout event) before it'll respond to "is item missing".

  • Haven't used LocalStorage in a bit so maybe I'm not remembering correctly, but, I think you need LocalStorage to run a "check if item exists" (you can stick that into the On Start of Layout event) before it'll respond to "is item missing".

    I did exactly what you are suggesting, but still not working

  • Hmm, well looks like the last project in which I used a storage it was a WebStorage instead of Local. Guess I got nothing, maybe see if this tutorial on LocalStorage can help solve the problem. It's got examples you can try.

  • Hmm, well looks like the last project in which I used a storage it was a WebStorage instead of Local. Guess I got nothing, maybe see if this tutorial on LocalStorage can help solve the problem. It's got examples you can try.

    Thank u so much, I already red this tutorial before, it didn't help either but I managed to get what I wanted exactly with system save & load.

  • Hi,

    I also want to use the levels with last score save in game, If possible can you please share the screen shot.

    So I can understand, how to write the event.

    Thanks,

    RW

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Before you end your layout put Event to save data to local storage

    something like this :

    System>End Of Layout : LocalStorage>Set Item>"key_name" to level

    But you need to decalre more event to load that localstorage in your SELECT LEVEL MENU,

    you should ask the localstorage exist or not on start of layout. after that you can set global variable to LocalStorate

    1. System>On Start of Layour : LocalStorage>Check item exists>"key_name"

    2. LocalStorage>On Item Exists>"key_name" : LocalStorage>Get Item>"key_name"

    3. LocalStorage>On Item Get>"key_name" : System>Set Value>level>LocalStorage.ItemValue

    4. LocalStorage>On Item Missing>"key_name" : LocalStorage>Set Item>"key_name">level

    You can use it for highscore. But needed more event and action.

    NB : blue color are Global Variable

    and the italic is Key Name (You should Type it manualy with the "quotes", for example "key_name")

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