Dictionary - on loaded?

Discussion and feedback on Construct 2

Post » Tue Nov 03, 2015 3:40 pm

Hi.
I'm working on a project where I load the dictionary from JSON.

How can I know when the data from JSON is loaded into the dictionary? I use "function" to get data, and load from "function.call" (return value).
B
32
S
7
G
4
Posts: 407
Reputation: 4,614

Post » Tue Nov 03, 2015 4:10 pm

Dictionary.Load is immediate. It's not technically "loading" from a stream. It's taking the already stored JSON string in memory and then converting the JSON into the Dictionary storing mechanism. So there is no need for when Dictionary is finished as it's finished the moment the action is done. you can start using data in the same event.

So
Start -> AJAX.Load( file )

AJAX.OnLoad -> Dictionary.Load( Ajax.lastdata )
-> Dictionary is ready to use.
B
94
S
18
G
9
Posts: 2,457
Reputation: 15,167

Post » Tue Nov 03, 2015 4:25 pm

Seems right ... But it sometimes happens that, if I have "Dictionary|Is empty" condition just after the "Load" action, it recognizes it as empty. Is it possible that it's because I'm calling function?
B
32
S
7
G
4
Posts: 407
Reputation: 4,614

Post » Tue Nov 03, 2015 5:33 pm

grigrizljac wrote:Seems right ... But it sometimes happens that, if I have "Dictionary|Is empty" condition just after the "Load" action, it recognizes it as empty. Is it possible that it's because I'm calling function?


Do you mean within the same event, or two different events?
Banned User
B
50
S
24
G
14
Posts: 637
Reputation: 12,503

Post » Wed Nov 04, 2015 2:40 pm

Here's my code:
Image
Image

But if I do like this, it doesn't work (sometimes works, usually not):
Image
B
32
S
7
G
4
Posts: 407
Reputation: 4,614

Post » Wed Nov 04, 2015 5:44 pm

@grigrizljac that looks pretty funky. I am having trouble determining exactly why you are doing, what you are doing with that fragment. Do you have your capx to look at?
Banned User
B
50
S
24
G
14
Posts: 637
Reputation: 12,503

Post » Wed Nov 04, 2015 5:49 pm

@humanescape I get the data from Local Storage, then call a function to decrypt it, and what is returned, I load into the Dictionary.
With "Is empty" I want to check if the data was OK, not corrupted.
B
32
S
7
G
4
Posts: 407
Reputation: 4,614

Post » Wed Nov 04, 2015 6:07 pm

grigrizljac wrote:@humanescape I get the data from Local Storage, then call a function to decrypt it, and what is returned, I load into the Dictionary.
With "Is empty" I want to check if the data was OK, not corrupted.



Yes, but how are you storing it? When are you calling the store/retrieval? I don't see anything wrong with that snippet of code. I could be overlooking something, but the issue could be elsewhere.
Banned User
B
50
S
24
G
14
Posts: 637
Reputation: 12,503

Post » Wed Nov 04, 2015 7:38 pm

It seems everything works now. Thanks for help and replies. :)
B
32
S
7
G
4
Posts: 407
Reputation: 4,614

Post » Wed Nov 04, 2015 8:54 pm

grigrizljac wrote:It seems everything works now. Thanks for help and replies. :)




Glad it worked out. What was the solution
?
Banned User
B
50
S
24
G
14
Posts: 637
Reputation: 12,503

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests