How do I write multiple dictionaries to a single save file?

Get help using Construct 2

Post » Fri Jan 13, 2017 8:18 pm

I'm currently using a .json file to save and load my player save data. I want to use a separate dictionary for some other data, but I want to be able to write both dictionaries (and possibly arrays) as a single save file on the player's computer. Is this possible using the single .json file? Or will I have to write multiple .json files and somehow zip them into a new file?

The "append file" action in NW.js would work to save additional dictionaries, but when I load that data, how would C2 know to separate the data into the correct dictionaries?
B
24
S
6
G
1
Posts: 46
Reputation: 1,892

Post » Sat Jan 14, 2017 1:41 pm

I would create a new dictionary called 'Master'. For each of the dictionaries you want to save, create a key named for that dictionary, and make the value of that key the dictionary's .json. When you load the Master dictionary, simply set each of your dictionaries to load the JSON from their key using Master.Get(#Dictionaryname) :)

I use this technique a lot, it works perfectly :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sat Jan 14, 2017 4:14 pm

That's a very smart way to do it! Thank you!
B
24
S
6
G
1
Posts: 46
Reputation: 1,892

Post » Sat Jan 14, 2017 4:16 pm

I assume this is just as easily done with a combination if dictionaries AND arrays inside the master dictionary?
B
24
S
6
G
1
Posts: 46
Reputation: 1,892

Post » Sun Jan 15, 2017 1:48 pm

Indeed. JSONs nest very nicely to create very complex data structures.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests