How do I save a character unlocked?

0 favourites
From the Asset Store
Template for a generic save / load system, fully documented in comments and video
  • Hi there, I've got another problem

    So, I made a shop for my game for unlock characters, and with this solution is ok.


    (Under the ShopButton to buy, there is a SetButton to select the character choosen)

    (ShopButtons.Prezzo is a Instance Variable to make the price different for every button)

    The problem is when I close the game, in fact, when I reopen it, I have to buy again all the characters unlocked previously. Is there a way to save the progress? I know that with the WebStorage I can save variables etc. but I don't know how to apply this method on more sprite all identical. (ShopButton)

    Thanks in advance!

  • You must have the bought characters stored anywhere. It could be a server or a local Webstorage object, I don't know the requirements of your game so I can't tell which one you should choose. And, then, you must check them when you load the game.

  • Thanks, I know this method but I don't know how apply this method here.

    This is my capx, if you want to look at it I'd be happy.

    Feel free to change it if you want and give back to me correct ... hop.caproj

    The main problem is how to maintain the character unlocked after closing the game.

    Thanks in advance!

  • Why don't you just use the persist behavior ? once destroyed it will never be come back

  • Naji That's exactly the problem. The idea is to keep bought characters available between two sessions.

    Fiammaoscura Could not open the file. Save it as a single file (.capx) and send it again.

  • Here's an example:


    I edited a lot of stuff. Joined both buttons as different frames of the same button, added an array with information about the characters and the position of buttons, so you can add others, etc.

    Let me know if that was what you were trying to achieve.

  • WOW! You're awesome! Thank you very very much!

    One last little thing, one last question, if, as you said, I want to add other buttons, what should I modify? Only the JSON strings or even other things in the event sheet?

    Thanks for your time and your patience!

  • Hi Fiammaoscura,

    Sorry for the delay... New years and stuff.

    You just have to add a line in the JSON array to add a character. I made an example with 3 characters.

    Also, I corrected an issue with the loop that creates the Webstorage objects, which was just creating 2, not as many as necessary. It does now.

    Lastly, I added a Webstorage object to save the money. It is created the first time the player runs the game and is set to the value stored in STARTING_MONEY. And I added a text element to show us the amount of money the player has...

    Here it is:


  • Don't worry, you did a great job I'm grateful. Thank you very much!

    You should write a tutorial, there isn't a tutorial to make a shop so detailed

  • brunopalermo

    I would like to ask if that greatmethod you used also works if the game is exported as exe (node webkit)?


    nice game

  • Never exported using node webkit, but I believe it should work fine,

    Fiammaoscura I like the idea of writing a tutorial about this. I'll work on that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't suggest to use webstorage for this kind of stuff...

    I mean, if there is a shop in your game,for update something etc...and use coins or other things and the player just remove all cache (I remove the cache of the browser 5 time a week) he will lost everything.... also some software clean all cache of the browser for safe...

    I suggest you to use a server to save a personal data for every user, it's easy and fast, and the savegame can be open in different computer...

    also, if your game is for the nodewebkit, you can store in the computer (some folder...) If I remember

  • Ribis

    How to save? I haven't tried that and no idea so far

  • Ribis

    How to save? I haven't tried that and no idea so far

    You have to send a data with AJAX (like JSON string...variables...etc) and use php to save the file or send variable to your database...

    In my game, I save all of the data on my server, every level has the json file in the folder of the user, to save the progress of every level, and I store the coin, life, update of the user....etc in a database

    1° make a registration page (very easy, just let's make an user, pass and choose a random ID), if it's for facebook, you make a registration at the start with his UID, username, email...etc

    2° Contruct2, will send a data (user,ID,password,email...etc) via AJAX to a php file, and the php file will insert the data on your database, and also, you can make a folder from the ID of the user in your server.

    3°now, the problem it's when save the data... for the most of the game you don't have to think so much about this, for example, for the most game, you can use a checkpoint, a savegame button...etc... so, very easy, and you can store the savegame of the level in your server (think about a tilemap, if you destroy a terrain, collect some special item...)

    4° now, in my game, I send a JSON string from the Array, and my php file will make a file in .JSON in a folder of the user with the name of the level.

    5° at the start of the game, construct2 will load the variable of the database, and check if exsist any savegame for the level, if there is a savegame, just load the JSON file.

    just simple script of php, you can find everything on the web and in a official manual of php

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