0 Favourites

How do I make an array based saving system?

  • 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 <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

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

  • 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.

  • I still need help btw.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • Use set at X,y to load the array.

    You need to setup the array first so it has enough slots for your purpose.

  • 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.

    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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
234 61,227
DARKSETH's avatar
DARKSETH
Unread hot topic
167 14,491
DMT2005's avatar
DMT2005
Unread hot topic
152 19,231
Magistross's avatar
Magistross