How do I make an array based saving system?

Get help using Construct 2

Post » Wed Nov 04, 2015 10:06 am

Hi I have been struggling with this problem for a few days now. I am trying to make the game load levels made in a level editor saved in folders on the computer, I am using NW.js. I have figured out how to save, each level is its own folder and each folder currently has 2 files in it one .TXT with a JSON string for the tilemap and another .TXT with a JSON string for an array I use to save objects. I have figured out how to load the array and the tilemap into the game, but not how to load the objects from the array.
I am also using the nickname Plugin/Behavior to spawn the objects.

.capx: https://www.dropbox.com/s/o8sb9nf79ugqr ... .capx?dl=0

The menu layout isnt even slightly implemented, just overlook it.
Thanks for the help :D
Last edited by BunnehBoy on Wed Nov 04, 2015 1:26 pm, edited 1 time in total.
B
8
S
2
Posts: 24
Reputation: 536

Post » Wed Nov 04, 2015 10:17 am

in a nutshell, load all the JSON data int a single array, and save the array as a json file.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Wed Nov 04, 2015 10:58 am

jojoe wrote:in a nutshell, load all the JSON data int a single array, and save the array as a json file.

I am able to load the array into the game, but cant figure out how to load objects from the array.
I am using the for each XY element loop. I dont know if I am using it correctly
The array contains the objects nickname on y0 and the JSON info on y1.
B
8
S
2
Posts: 24
Reputation: 536

Post » Thu Nov 05, 2015 1:19 pm

I still need help btw.
B
8
S
2
Posts: 24
Reputation: 536

Post » Thu Nov 05, 2015 5:34 pm

Not sure if this would be the right way, but you might need to save x, y locations of all objects, and objects UID in the array, and on game load, you would have your script to create objects based on the data in the array,
for example:

arrayData: 1,4,1
Index: 1 (Object UID), (X Location), (Y Location), (Layer), etc......

Edit: changed the If to a foreach
so when game starts | foreach {arrayData.at(arrayData.IndexOf(object.UID), 1)} (CreateObject Object, SetPosition.X (arrayData.at(arrayData.IndexOf(object.UID), 2), SetPosition.Y (arrayData.at(arrayData.IndexOf(object.UID), 3), SetLayer (SetPosition.X (arrayData.at(arrayData.IndexOf(object.UID), 4)))

now I am at work and do not have construct open, but this is what I see in my head right now. I could be way off as well.
Last edited by mordiaky on Thu Nov 05, 2015 6:11 pm, edited 5 times in total.
B
8
S
1
Posts: 74
Reputation: 725

Post » Thu Nov 05, 2015 5:58 pm

Use set at X,y to load the array.

You need to setup the array first so it has enough slots for your purpose.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Thu Nov 05, 2015 8:36 pm

You can't create an object based on UID, I use the nickname plugin/behavior for that. As I said I have already made the game save its objects to an array. And I have managed to get the array loaded into the game. A few minutes ago I managed to load the objects by nickname from the array, but I cant figure out how to set the JSON state to the correct objects through picking etc.
mordiaky wrote: Edit: changed the If to a foreach
so when game starts | foreach {arrayData.at(arrayData.IndexOf(object.UID), 1)} (CreateObject Object, SetPosition.X (arrayData.at(arrayData.IndexOf(object.UID), 2), SetPosition.Y (arrayData.at(arrayData.IndexOf(object.UID), 3), SetLayer (SetPosition.X (arrayData.at(arrayData.IndexOf(object.UID), 4)))

I am already using a for each.

Updated .capx (figured out how to load the objects, not how to set the JSON string from array, picking the correct instances etc.): https://www.dropbox.com/s/77c3rxdyu5ptz ... .capx?dl=0
B
8
S
2
Posts: 24
Reputation: 536

Post » Sat Nov 07, 2015 10:28 pm

I figure it out, I just had a problem with my events. Used an at with the for each element loop instead of testing for the current Y and then trying to pick the correct instance.
B
8
S
2
Posts: 24
Reputation: 536


Return to How do I....?

Who is online

Users browsing this forum: guannstar, odiusfly and 21 guests