Dictionary.AsJson doesn't save instance variables????

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hey,

    I think I must be missing something... when I was inspecting Json strings generated by construct using dictionary.AsJson, it seems that they don't include instance variables like they do for sprites. Am I missing something or is this true? Wouldn't that be a major bug if so or is it intentional?

  • You mean the dictionaries instance variables?

  • Probably a bug I suppose. Arrays probably don't save them either I'd imagine with the .asJson expression. It doesn't mean the variables aren't saved with the save and load actions (can't look at the source to check right now).

    Actually I can also see why it might not be a bug. As it is now any .asJson of a dictionary can be loaded into any other dictionary. If it saved instance variables too it would be like Sprite types where I assume you can only load a json string saved from the same type.

  • expression:AsJson in Dictionary:

    JSON.stringify({
        "c2dictionary": true,
        "data": this.dictionary
     }[/code:1y1phh1h]
    
    It does not save instance variables indeed.
  • two different actions Set & Load

    Set from JSON for List object

    {"c2":true,"ivs":{"345726035289035":99,"4920281471186917":"test"},"w":{"x":437,"y":64,"w":150,"h":22,"l":7960705071762816,"zi":2,"hX":0,"hY":0},"data":{"tooltip":"","disabled":false,"items":["Item 1","Item 2","Item 3"],"sel":[0]}}[/code:2nunqofn]
    
    Load from JSON for List object
    [code:2nunqofn]{""c2list"":true,""data"":{""items"":[""Item 1"",""Item 2"",""Item 3""]}}[/code:2nunqofn]
    
    Load from JSON- loads only [i]"data" [/i] for Dictionary..
    
    [code:2nunqofn]{"c2dictionary":true,"data":{"animal1":"dog","animal2":"pig","animal3":"cat"}}[/code:2nunqofn]
    
    there is [i]no Set from JSON[/i] action for [i]Dictionary[/i] and no Load from JSON for List object...
  • BTW, as far as I remember using loading instance from asjson, it wasn't given new uid, and was ending up with several object with same uid. Not sure if that has been fixed or not thought.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • megatronx - egh, I better check that. I don't think I ever pick dictionary by uid, but... that could make things go squirly in some cases!

  • korbaach - ah, thats a distinction to note. I imagine its intended then. But what would the purpose of instance variables be then on such an object? I was using them to store dictionary.asJson strings to load the same object to a previous point. I was concerned this wouldn't work depending, but since it doesn't change them it works out lol.

  • You mean the dictionaries instance variables?

    yeah, not the data in the dictionary itself. Just instance variables.

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