So you’re using the array so that its size is:
(Count, numProperties,1)
And you access values with:
Array.at(n,property)
Where n is the index to the object and property is:
0 for x
1 for y
2 for zindex
3 for name
… and so on if you add more properties later on.
Looks like you already have saving down but here is an example. You can set the array size first and just fill in values but I find it’s easier to increase the size as you add objects, especially if you have multiple types you’re saving. Anyways, “push” or “insert” basically will change the size of the array, but to be super clear about it you can just set a new size like here.
On function “save”
— array: set size to (0,4,1)
— for each sprite
— — array: set size to (self.width+1, self.height,1)
— — array: set at (self.width-1, 0) to sprite.x
— — array: set at (self.width-1, 1) to sprite.y
— — array: set at (self.width-1, 2) to sprite.zindex
— — array: set at (self.width-1, 3) to “sprite”
For loading you’d still do “for each x element” instead of xyz. And you’d use array.at(n,3) to get what the name of the current object is.
On function “load”
Array: for each x element
— compare: array.at(array.curx,3) = “sprite”
— — create: sprite at (array.at(array.curx,0), array.at(array.curx,1)
Now a further improvement so it actually loads the objects in the same zorder as you save it is to rearrange the order of the values to {zindex,x,y,name} and sort it. That would only change the save function.
On function “save”
— array: set size to (0,4,1)
— for each sprite
— — array: set size to (self.width+1, self.height,1)
— — array: set at (self.width-1, 0) to sprite.zindex
— — array: set at (self.width-1, 1) to sprite.x
— — array: set at (self.width-1, 2) to sprite.y
— — array: set at (self.width-1, 3) to “sprite”
— array: sort by x