Unlocked Extras System

  • In my game, you can unlock pictures and clips using points you've earned as part of the Extras. Now I'm trying to figure out how to keep whatever has been unlocked saved into the game.

    I'm using local storage to save my game levels and such (arrays are still somewhat confusing me). Even though I can probably come up with an event sheet that updates every single extra item, I have no idea how to save that in the local storage. If arrays are the only way to go then so be it. Any help would be appreciated.

  • I think the Dictionary is better suited for this task.

    When an item is unlocked, add a new key to the dictionary. Save the dictionary to local storage the same way you save your arrays. (AsJSON)

  • Use google translator spanish to english

    Hay una forma facil y otra un poco mas dificil

    Facil

    Usa Save And Load

    scirra.com/tutorials/526/ho ... vegames/es

    "Dificil"

    Usa LocalStorage

  • I think the Dictionary is better suited for this task.

    When an item is unlocked, add a new key to the dictionary. Save the dictionary to local storage the same way you save your arrays. (AsJSON)

    OK, I've tried using the Dictionary. I'm having no problem adding a key/value and that part works very well. What I can't do is get the .Json to load at the start of the game. I even tried to save the name of the .Json file into my local storage to retrieve it at the start but it's not working. One of the things I notice is that the Dictionary will download a .Json and add a () number because the file name is similar.

    Again, I haven't used arrays because they are confusing me for some reason. This will probably be the very last thing I have to add to my game in terms of working systems. If I can get an example .capx or even a video that explains how to retrieve .Json files/data then maybe I can get this working. Even now, I can see how Dictionaries could be used to store pretty much anything.

  • Not .json file, I meant .AsJSON expression.

  • Not .json file, I meant .AsJSON expression.

    OK, now I'm able to add to the Dictionary AND set everything in it to Local Storage AND load from JSON string.

    So how would I get my game to check if the extra that was unlocked? Each extra (with Persist behavior) has an instance name and that is what's entered into the Dictionary as a key, and the Dictionary is saved to .AsJSON with every unlock. I can see the Dictionary with every key when I reopen the .capx. So now I'm trying to understand how Construct 2 looks through a Dictionary and retrieves the key/value.

    Also, could I have saved the unlocks in the local storage? Would that have been a bigger hassle/mess because I can see how it could.

  • I can see the Dictionary with every key when I reopen the .capx. So now I'm trying to understand how Construct 2 looks through a Dictionary and retrieves the key/value.

    Do "Dictionary for each key" after it's loaded from local storage, and update your extras sprites.

    Also, could I have saved the unlocks in the local storage? Would that have been a bigger hassle/mess because I can see how it could.

    Sorry, I don't understand what you mean. Aren't you already saving unlocked extras in the dictionary and in local storage? What bigger hassle are you talking about?

  • > I can see the Dictionary with every key when I reopen the .capx. So now I'm trying to understand how Construct 2 looks through a Dictionary and retrieves the key/value.

    >

    Do "Dictionary for each key" after it's loaded from local storage, and update your extras sprites.

    > Also, could I have saved the unlocks in the local storage? Would that have been a bigger hassle/mess because I can see how it could.

    >

    Sorry, I don't understand what you mean. Aren't you already saving unlocked extras in the dictionary and in local storage? What bigger hassle are you talking about?

    OK, I'm not sure exactly what to put after "Dictionary for each key". I made it so that the key/value system enters the "Name"instance variable/"UID". And I am able to unlock only the 1st key in my Dictionary and not the rest.

    I've tried "Start of Layout" and "Every Tick". Before I didn't realize I was working on the wrong even sheet. Now this is the step I'm stuck at. Hopefully this pic works to show you what I have.

  • On your screenshot the "For each key" event is executed every tick, which is wrong.

    You need to move it to "Local storage item exist", after you've loaded the dictionary from local storage.

    Also, you should remove subevent #3.

    And if the "Name" instance variable is unique for each item, it's better to pick a_PicPreview by Name, rather then by UID.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On your screenshot the "For each key" event is executed every tick, which is wrong.

    You need to move it to "Local storage item exist", after you've loaded the dictionary from local storage.

    Also, you should remove subevent #3.

    And if the "Name" instance variable is unique for each item, it's better to pick a_PicPreview by Name, rather then by UID.

    Finally, I've been able to get this to work. It seems to be that you can load the Dictionary once you need it instead of just at the start of your game. This was really making me nuts but now I'm seeing how it works. Thanks again.

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