How do I save with LocalStorace all instance variables about Array object?

Not favoritedFavorited Favorited 0 favourites
  • 12 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi, I’m looking for a way to save all the instance variables of an object using an Array and LocalStorage. Unfortunately, I tried using .AsJSON, but it seems like nothing gets saved. Is there any way to easily save all the instance variables of an object through an Array?

  • Hello, I hope I have understood the question correctly.

    Here is a simple example.

    fex.net/s/ll4z4ac

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, but the issue is the Array’s instance variables — they seem impossible to save using LocalStorage.

  • Thanks, but the issue is the Array’s instance variables — they seem impossible to save using LocalStorage.

    What are these variables that you want to save but can't? Give me an example, I don't understand.

  • > Thanks, but the issue is the Array’s instance variables — they seem impossible to save using LocalStorage.

    What are these variables that you want to save but can't? Give me an example, I don't understand.

    these

  • these

    It's pretty simple, you save it and load it like a regular variable.

    fex.net/s/fzatrtm

    But your data storage option is pretty tedious, I can't imagine why you added 16 local variables to the archive, but I can easily imagine your sad mood when you process or change them.

    I'm not usually that stubborn, and anything that requires more than three repetitions, I try to process using a loop and an array or dictionary.

  • Can't I save all Array Instance Variables at once?

  • Can't I save all Array Instance Variables at once?

    No.

    These are just local variables of the object, just like on sprites or other construct objects. The fact that you have attached them to an array object does not give you any improvement.

    Perhaps you could tell me how you work with the data in the variables “map01...map16” so that I can advise you on a more convenient method of use and storage.

  • I think I have a huge problem. I have seven Array objects with about 30 instance variables each to save in local storage lol... It's crazy that I've only just realized this problem that breaks everything. Anyway, thanks.

  • I think I have a huge problem. I have seven Array objects with about 30 instance variables each to save in local storage lol... It's crazy that I've only just realized this problem that breaks everything. Anyway, thanks.

    This looks pretty good for the array structure.

    The rows can be map numbers, and the columns can correspond to one of seven objects. Then it will be convenient to refer to them and store them.

    It will also be convenient to fill in the initial data via the file.

    But you will need to spend time changing this.

  • I’ll probably be quicker just saving every instance variable.

  • That seems like a poor data organization to me - why do you have so many instance variables on the array? Why don't you store these values in the same or a in different array, or in a dictionary?

    Anyway, you can copy these values to a dictionary and save the dictionary in Local Storage. When loading - copy them back from the dictionary to instance variables.

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