Arrays - Instance Variables - AsJSON

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Do the instance variables of an array get stored in the AsJSON method?

    Problem: When I load an array from JSON the instance variables don't seem to load.

    Considering that the JSON only shows object type, array size, and the cell values, I'm not too surprised.

    Suggestion: Considering we have scenarios such as tile-maps where you can save the object as JSON(.AsJSON) or the tile state as JSON (.TilesJSON) is there a reason this can't be done for arrays? As of now it seems to act as a TilesJSON method of saving rather than the full object state.

    This suggestion assumes that my problem is a global occurrence and not a result of an error in my events.

  • The .asJSON expressions generally deal with the content of a data structure type of object (array, tiles, dictionary...).

    The instance variables are part of the object type, not the content of the current instance of the object.

    If you want to save the values of your instance variables, you would likely have to save them in addition to the .asJSON value, on their own.

    You could serialize your own string.

    For example:

    myFullString = array.asJSON & "¤" & array.variable1 & "¤" & array.variable2

    When you want to load the information from 'myFullString' into the array, you would use the tokenat() system expression.

    array action load : tokenat(myFullString,0, "¤")

    Set array instance variable : variable 1 = tokenat(myFullString,1,"¤")

    Set array instance variable : variable 2 = tokenat(myFullString,2, "¤")

    Here, the separator "¤" is a character that likely will not be used in the asJSON content and/or instance variable value.

    If you want to save the state of an object, use the dedicated system action :

    This will save the content of your object, as well as its instance variables.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Good point, I opted to just use the storage of the data object itself, but tokenat is another route I could take, thanks.

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