[SOLVED] LocalStorage, saving and away time?

0 favourites
  • 6 posts
From the Asset Store
Time rewind like in "Braid". Choose objects that will be affected by time rewind
  • Hey guys,

    i need some hands for my test. Im trying to get stuff like local storage, away time etc to work.

    But somehow it doesnt work as expected. If it comes to variables and math, my brain goes afk.

    Can someone help me fix this or give me instructions :( ?

    Im using the date plugin to get the unix time every tick.

    On start of layout, i check if 3 storage things exists ( current currency, timeaway, saved time)

    if not, they will created

    if they do, i set the variables to saved storagefiles

    If i click a save button, the current time will save the current unix time to a variable.

    Then i will wait some minutes (because its supposed to get every minute i went offline)

    After i reopen the game, nothing realy happens, no variables are set, but storage whise they seem to exist.

    Hope you guys can help me with my problem :/


  • Couldn't figure out but I do have a system of my own for that, 2 lines long and uses UTC plugin. If that helps at least, here you go: https://drive.google.com/file/d/1AEYmfXPWXSb0GhwqgVrjEzo0KPTQUTjf/view?usp=sharing

  • sassix

    there are a couple issues with your file - you never save the OfflineTime variable, except for the first time it is run (when the local storage item is missing - and it is set to 0). And you don't really need to save that in local storage because the SavedTime is doing the same job.

    Also, at the start of layout you check for the local storage items and then set the text fields before the items are finished loading from local storage.

    And when a localstorage item exists, you set its value back to 0 instead of setting your global variables with the value from localstorage.

    when you load items from localstorage, you don't know what order they will get loaded in, so you can't do any calculations until you are sure they have all been loaded. So, I changed it so that it calculates the time away when the SavedTime item is loaded and calculates the GoldEarned, but it doesn't add it to CurrentCurrency because that item may not have loaded yet. I only add it when you click the Quit button - where it sets the SavedTime and saves the new CurrentCurrency.

    when you click the Quit button, it starts saving the localstorage items and then closes the browser. I wasn't sure it C3 would know to wait until the items were saved before closing down - and it seemed like the values didn't get saved once or twice in testing, so I made it wait until the items finished saving before quitting.


  • Wow guys i appreciate your help so much! Thanks for that.

    Im realy confused when it comes to things like that. I dont realy know what to say.

    I also tried to use wait time before the game closes but i never thought that loading the storage could be in a different order then i placed them in the action :/

    Im trying to get used to this method, because now i cant start making my app which contains more variables :/

    Thank you very much, both of you for spending time on me !!

  • Another option is to put all the variables in an array, and save the array in local storage. That takes one save and one load, and then you know you have all the variables at once.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I did this tutorial to get time away or offline earnings , elapsed time if somebody needs it


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