0 Favourites

How do I save and load objects from an array?

  • How do I save and load objects from an array?

  • Maybe something like this to save if you just want to save positions.

    Set array size to (Sprite.count, 2, 1)

    For each Sprite

    --- set array at (loopindex, 0) to Sprite.x

    --- set array at (loopindex, 1) to Sprite.y

    Then maybe this to load:

    Array: for each X

    --- create Sprite at array.at(array.curx,0), array.at(array.curx,1) )

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Another thing you can look at is the .asJSON expression and the "load from json" action. Every object has them and you can use that to save only objects that you want.

    Here's an example:

    The saving saves three values for each object:

    "zindex" so the when we load they zorder will be the same.

    "name" so we can know what object to load.

    ".asJSON" the actual object data.

    after all that is put in the array it sorts the array by the zindexes, so then the array has each object that needs to be created in order of z.

    Loading is simple enough, and we use the "name" to create the right object type, and then the json is loaded.

    The capx has some comments of what you can do and what would require further implementation. Globals could be saved too but I'll leave that as an exercise for the user.

    But actually the more you want to save the more you probably should just use the save/load actions included with C2. You can use the "no save" behavior on objects you don't want to save.

  • R0J0hound Dude. Your dropbox links, all down.

    How we can download your capx?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)