Dictionary to LocalStorage to Dictionary using Json

Get help using Construct 2

Post » Fri Jul 14, 2017 10:27 am

Can I please have an example or a simple explanation of how to properly turn Dictionary Object into a Json String and place it in to LocalStorage, and how to get the Json String from LocalStorage and load it properly back into the Dictionary Object. I don't mind the use of 2 dictionaries to keep it simple, the concept is the same.

I can make dictionary object make a Json, but it asks to make a filename and I'm not sure why. From LocalStorage object I can seemingly do it directly without making a filename or even using the "dictionary make json" action. I'm not sure how to load it back into Dictionary or if I'm even loading it into LocalStoage Correctly. I think my problem is naming the location of the Json to load in.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Fri Jul 14, 2017 9:57 pm

I made a .capx.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Jul 15, 2017 1:36 am

Thanks, it saved me a lot of time.
I get it now for the most part, I do have it working.

I was missing ItemValue.
I didn't know of it until now, It doesn't work without it.

After a "Check Item Exists", do I have to add "On Item Missing" if I don't want to do anything if its missing?
What does the action "get item" do if item doesn't exist?

I think I don't have to add "On Item Missing" and "get item" doesn't do anything if item doesn't exist.
I just want to confirm, because LocalStorage is asynchronous.
I don't want to accidentally cause an issue.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Sat Jul 15, 2017 1:50 pm

Unconnected wrote:After a "Check Item Exists", do I have to add "On Item Missing" if I don't want to do anything if its missing?

Yes.

Unconnected wrote:What does the action "get item" do if item doesn't exist?

Nothing.

On Item Missing might be useful to report back to the user that something misses or to display available savegames.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Jul 16, 2017 2:22 am

Thanks again.

One last question.
If I have a key named the same as a variable, how do I use key name to set coinciding key to variable with same name?

Would like to use a "for each" instead of doing 1 by 1.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Mon Jul 17, 2017 3:46 pm

If you want to set a key, simply use the action "Set key" and for the key, you insert your variable.
If the variable is anything else than a string, make sure to wrap str() around it, since keys can only be strings.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Thu Jul 20, 2017 10:43 am

Thanks I got it.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 31 guests