Feature Request : Improve/New Local Storage

0 favourites
  • 14 posts
From the Asset Store
City ride is a game to improve your memory.You have to focus and remember the information related to passengers of previ
  • The idea is save all the events possible and do all in the properties and in an interface similar to the "instance variables".

    Every time i have to use the Local Storage plugin i have to read the doc and the examples, not's much intuitive at least for me and a bit frustrating to do some things.

    I want to do some kind of achievements/trophies to my game , i posted here () but put here a pic of what i mean:

    So, why not if we can get all in a "Local Storage" interface like the "instance variables" and properties in the object to automatize the process and avoid all this events.

    I made some interface using the actual things to show the ideas:

    So, we can add variables and set what value in case of missing, maybe 0, maybe a text saying "locked" or whatever and the moment we want this one gets saved.

    In the properties we have when load the storage keys. In this case on start the layout "Gameplay" load all the storage keys, in case some ones are missing we already have set the number/text. Other possibilities can be added, and if somebody needs to be more specify always can continue use the events. Or if there are some keys that we don't want to load maybe add another tab in the interface for each key saying "Yes/No" to be loaded using events for any reason.

    So, we have all this configured in a moment and without events, now is time to set/save values in the local storage... or not!. If we are using a Global Variable called Best_Score , we can link/pin to a Key in the "local Storage" and in their interface we already set when save it like On Change/On Start Layout/Every tick , etc....

    If you link a Global Variable to a Key in the local Storage, when the Keys in the Local Storage are loaded they also set the global variables. After that, when a global variable changes will change the key linked.

    Maybe there are things that can't be done for some reason, but as i said the idea is avoid all this events of: Read if exists, get item, set value, if key missing, blablabla.... get something more visual/intuitive and easy to access/use.

  • A common technique is just to load and save an entire Dictionary object's JSON which covers most of this.

    LocalStorage is asynchronous (i.e. setting/getting fires a trigger after a moment, rather than being immediately available) which means it can't really be mapped to anything synchronous (like setting/getting global variables). If a "get global variable" or similar turns in to a "get localstorage value", that value is not immediately available, and may fail as well. So that's not actually possible, without some kind of internal caching mechanism, which is basically the same as doing the save/load dictionary object technique.

  • The idea is save all the events possible and do all in the properties and in an interface similar to the "instance variables".

    ...

    To be honest, you can just forget working with it if you plan to use it on multiple platforms.

    Each platform comes with surprises that break the plugin in some weird way,

    without Ashley having a possible chance to fix it once and for all.

    So if you'd ask me, keep on using the old webstorage plugin for as long as you can, before it gets depreciated by the browsers.

    Both plugins work fine but the sync plugin saves a lot of events and stress on our side.

  • A common technique is just to load and save an entire Dictionary object's JSON which covers most of this.

    LocalStorage is asynchronous (i.e. setting/getting fires a trigger after a moment, rather than being immediately available) which means it can't really be mapped to anything synchronous (like setting/getting global variables). If a "get global variable" or similar turns in to a "get localstorage value", that value is not immediately available, and may fail as well. So that's not actually possible, without some kind of internal caching mechanism, which is basically the same as doing the save/load dictionary object technique.

    Then, instead of using linked global variables use Storage Keys as variables to use in events.

    So i create a key called BestScore in the storage. In events i can say that when the Player_score is greater than Key_BestScore set new.

    And the load/save/if missing,etc... the Local Storage keys is already covered in properties without events or use any other plugin like Dictionary or create events to load/save json,etc...

    Or if not is possible either the Local Storage variables add a instance variables properties in the Local Storage object that can be loaded/saved with some basic options as in my pics. And as always if somebody needs more deep things can use events.

  • I don't think any of that changes the basic fact that you can't pretend asynchronous code is synchronous. It breaks assumptions like the events will run in any particular order, which the existing system makes obvious by making you use triggers in a separate event. Anything which looks like a simple comparison/access but really is asynchronous in the background would be even worse than we have now - it would just silently break or fail to work as you expect in random situations!

    I wrote up an idea for a "then" event to try and make things like this easier, but it's not supported and I'm not sure how much it would really help anyway: https://www.scirra.com/forum/idea-make-async-easier-with-quot-then-quot-event_t128870

  • Once you figure out how local storage works, and keep in mind it is ASYNC, it is not that hard. You can write methods to make it easy as pie, or follow a certain technique.

    Your biggest challenge if you are not use to ASYNC methods, is to keep in mind the AYNC techniques. Once you understand that, it is easy. There are things to keep in mind, such as when to fire them, what to do if it takes awhile (blocking vs non blocking UI which has pros and cons), among other things.

  • I don't think any of that changes the basic fact that you can't pretend asynchronous code is synchronous. It breaks assumptions like the events will run in any particular order, which the existing system makes obvious by making you use triggers in a separate event. Anything which looks like a simple comparison/access but really is asynchronous in the background would be even worse than we have now - it would just silently break or fail to work as you expect in random situations!

    I wrote up an idea for a "then" event to try and make things like this easier, but it's not supported and I'm not sure how much it would really help anyway: https://www.scirra.com/forum/idea-make-async-easier-with-quot-then-quot-event_t128870

    Then a trigger on the event sheet on you say "load storage" and this event loads all the keys and sets to the variables you previously defined and in the case they are missing (first time running) sets to 0 or whatever you defined previously.

    And for save another unique event. Now i have to do "get item" event and after a "set item" event, or there is another way to do in a unique event? . If not, will be great simply when X happens set Key.BestScore(The local storage) to BestScore(Global variable).

    This is what i'm doing, is correct?

    There is no way to save the "get item" event? and in the comparision say something like:

    LocalStorage.key.BestScore

  • OP, why don't you just collect all external data on the start of your app and stored them inside dictionaries and arrays. Compute them there at blinding speed with zero problems. On exit, save or set interval, slot back the data into the local storage objects.

    It's pretty easy, no fuss and pretty much how all other people do it,.

  • 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 think any of that changes the basic fact that you can't pretend asynchronous code is synchronous. It breaks assumptions like the events will run in any particular order, which the existing system makes obvious by making you use triggers in a separate event. Anything which looks like a simple comparison/access but really is asynchronous in the background would be even worse than we have now - it would just silently break or fail to work as you expect in random situations!

    >

    > I wrote up an idea for a "then" event to try and make things like this easier, but it's not supported and I'm not sure how much it would really help anyway: https://www.scirra.com/forum/idea-make-async-easier-with-quot-then-quot-event_t128870

    >

    Then a trigger on the event sheet on you say "load storage" and this event loads all the keys and sets to the variables you previously defined and in the case they are missing (first time running) sets to 0 or whatever you defined previously.

    And for save another unique event. Now i have to do "get item" event and after a "set item" event, or there is another way to do in a unique event? . If not, will be great simply when X happens set Key.BestScore(The local storage) to BestScore(Global variable).

    This is what i'm doing, is correct?

    There is no way to save the "get item" event? and in the comparision say something like:

    LocalStorage.key.BestScore

    I think you need to take a step back and understand the fundamentals of async calls. what you are trying to do won't work. A quick google will bring you many results on the differences.

    The way you are trying to use it is how the old storage worked, it was a sync call. New standards of browsers that is deprecated as I understand it and you need to use async methods.

    Once you step back, and understand how/why it works, it is not bad at all.

  • The request could be separated into two parts,

    1. enumerate the variables in GUI like global/local/private variables

    2. save/load in synchronization mode

    Using a dictionary like Ashley said, could solve request2 only.

  • For Request 1, i would be happy allready if i could get the whole Local Storage a json (after all it is keys and values) and assign it to a dictionary (or the Local Storage should be formatted in the same way as a dictionary).

    For me that would be helpfull.

    About the get/set system i have no complains at all.

  • The request could be separated into two parts,

    1. enumerate the variables in GUI like global/local/private variables

    2. save/load in synchronization mode

    Using a dictionary like Ashley said, could solve request2 only.

    For point 1 i was thinking in something more like "instance variables" on you can add/remove, select position, set an initial value,etc... like the examples, something more visual/easy to manage.

    About the sync, i'm not a coder and after read some about that i'm still not understand very well XD(also english is not my native language), for that reason i'm using C2(Thanks for this great program!) ,my code skills are 0 so local storage, json's, arrays and similar things simply i can't with that and always i get frustrated to get something working, and maybe i finally got something but when i finish the game and go to another if i need to use it again, simply remember all the time i will have to invest to understand again and get it working i lose the motivation or avoid that feature.

    My first game using C2 was AsteroidX (https://www.scirra.com/arcade/shooting- ... roidx-4511) , was made in only 2 weeks. The unique time i get a bit stucked was using the Parse plugin for online Scores but finally i got things working great with more features that i planned in a first moment so this one worked great and was intuitive/easy to use.

    Now i'm trying to do a basket game cross-platform desktop/mobile/tablet using only the html5 version, this one: https://kronbits.itch.io/basket-prototype . And my idea was create some player stats of wins/loses/draws , gameplays, % of accuracy and lots of achievements but after see all i have to do for get working only one, to load the local storage keys and manage.... well i think i will do only the best score that is already working and maybe the wins/lose/results <img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz"> .

    Seems the way i planned have a problem with the sync, but sure there is a way to make it, if not more simply, more visual/intuitive on you can see in a first look how many keys you have in the local storage and manage them, load all integrating with the LocalStorage without using another plugin (the dictionary) and learn how json's works.

    So well, i don't know if this finally will be improved/redone or whatever, but thanks for the replies and the interest guys! <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

  • I See where you are gooing. But for that to work (i think) the sprite should accept json, (when i try it destroys itself) to link it direcly to the Local Storage in get and in set. Dont think that is for tomorrow.

    I would welcome an interface to see whats happening i the Local Storage. Althaugt, you can see the Local Storage object and its contents in the debugger.

    Currently. I avoid A sync by using an array and store its json. And i know whats in the array. Probaly why i cant complain. Guess i dont do complicated stuff with it. I also keep the user on a dead layout till all my stuff is loaded. Like this:

    ?

    https://

    drive.google.com/open?id=0B1SSuCVV8v74SnBseHRpUXRfSEU

  • I had another idea but maybe i'm falling again in the sync/async problem, but if not's the case here is:

    A temporaly LocalStorage, or maybe saving in memory while the game is playing, as variables that we can add/substract or some like that. I prefer Storage Variables so we can manipulate them and change more easily.

    Then an event to save to the real Local Storage like:

    Read TempStorage/Storage Variables > Save to Local Storage

    This "Save to Local Storage" event willl do:

    --------------------------------------------------------------------

    Get item Key1

    On item Key1 get - > Set item "Key1" to Temp.Key1

    Get item Key2

    On item Key2 get - > Set item "Key2" to Temp.Key2

    etc....

    In the same way now we do that, only that he will do automatically for us starting to get the first key defined until the last one. Same thing for the load.

    So, we have a Storage Variable like Global Variable that we can manipulate, if we change his name, in all the sites appears in the even sheet will change (like global variables), the option to add/substract for numbers and all this things.

    In the GUI we have that variables in X order, and set in case of missing what number/text set to default when load.

    The event mentioned to load /save like the Dictionary/Json's trick for all the keys and the option to load/save only one of them in case we need that.

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