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

Discussion and feedback on Construct 2

Post » Fri May 13, 2016 1:49 am

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?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Fri May 13, 2016 1:54 am

You mean the dictionaries instance variables?
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Fri May 13, 2016 3:52 am

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.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Fri May 13, 2016 4:05 am

expression:AsJson in Dictionary:
Code: Select all
JSON.stringify({
    "c2dictionary": true,
    "data": this.dictionary
 }


It does not save instance variables indeed.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Fri May 13, 2016 4:30 am

two different actions Set & Load

Image


Set from JSON for List object
Code: Select all
{"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]}}


Load from JSON for List object
Code: Select all
{""c2list"":true,""data"":{""items"":[""Item 1"",""Item 2"",""Item 3""]}}


Load from JSON- loads only "data" for Dictionary..

Code: Select all
{"c2dictionary":true,"data":{"animal1":"dog","animal2":"pig","animal3":"cat"}}


there is no Set from JSON action for Dictionary and no Load from JSON for List object...
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Sat May 14, 2016 3:08 am

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.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sat May 14, 2016 6:29 pm

@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!
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Sat May 14, 2016 6:33 pm

@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.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153

Post » Sat May 14, 2016 6:34 pm

newt wrote:You mean the dictionaries instance variables?


yeah, not the data in the dictionary itself. Just instance variables.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153


Return to Construct 2 General

Who is online

Users browsing this forum: Huemerson, jobel and 2 guests