For the next revision of my game, i’ve tried to add a saving system that saves 4 parallel arrays with information about the tilemap, however, i think the game runs out of memory before the level can be saved. I have seen this already being done but i only almost got it working.
I wanted to ask what i could try among, trying to save the information onto the settings by bits, use the existing array with tile images for loading so that the image array can be a number, or something else! Let me know what you think i should (or can) do.
Interesting, though this is just very close to using the existing array I have to identify tile images when loading. It looks like a good idea though, as i could assign each tile to a letter or a number, and i doubt i would run out of characters to use. I will just try this first and see if the game handles it better.
my actual advice would be to not do this; instead, store the changes to the tilemap instead of the entire things. unless you’re making a minecraft style game where every tile can be changed, this approach will likely be much, much more efficient.
with that being said, if you absolutely must save the entire tilemap to settings then here is how i would do it:
first, assign every tile in your tileset a number. for example, you could create one giant array called “allTiles” and use the index in that array as the number id for each tile.
then, when saving the tilemap you can save an array of numbers instead of an array of images (images stored with the better settings extension take up a LOT of storage space, so I would not recommend using that function).
I have an extension that lets you load tilemaps from a number array, so combining Richard’s idea with that extension would make it a lot easier. Each number in the array correlates to the position of the image of that tile in the tile set array, so the number 0 is the transparent tile, etc etc.
@WoofWoof and @richard , thank you for your help! I ended up just using a number array, and the map loading back in a weird way was caused by the data being inverted for some reason. It works like a charm now, even if i had to make the Tilemap smaller:
Even though the game now ignores transparent tiles when saving, i am still afraid of making it bigger since if someone makes a really big thing the game will crash. You do need to first press “Clear saves” though, since you can’t safely check if something is undefined.
There is a block for checking if a setting exists as well as one for getting a list of all settings if you wanted to implement proper load checking and a menu of worlds to load.
I have updated WoofWoofCodes/pxt-tilemapGen with this code. You’ll have to import the actual settings extension if you want to do anything other than save/retrieve these tilemaps (for example deleting them) but it’s functional and stuff, so have fun!