https://makecode.com/_62T7dF62M0UE
Hello, when you activate the red button, it will remove the red blocks, but if you run into a spike and restart the level afterwards, the red blocks are still removed even though the game reloads the tilemap. (8x8 assets are still there because i cannot remove them)
Also tried not using a transparent tile for replacing the red blocks, doesnt help.
it’s likely changing the actual data of the tilemaps
you’re storing your levels in an array instead of recreating them each time you load a level. that means that changes will persist if you set the tiles in the map, turn walls on/off, etc.
if you don’t want the one you’re storing in an array to be updated, you can always use the clone block from tile util to set the current tilemap to a clone instead of a reference to the stored one:
1 Like
I’ve seen the editing of an asset within an array before, can we also do this with other asset types?
yup, there’s nothing special about arrays though. the real thing is just that you’re keeping a reference to the same object
for example, let’s take a look this program:

the loadLevel function is creating a new tilemap every time it is called. if you were to modify the tilemap by pressing the A button, that change will not persist when loadLevel is called a second time. you can click on that image to try it out.
now if we take the same program and use a variable:

this time we’re only creating the tilemap once and we’re keeping a reference to it in the myTilemap variable. if the tilemap is modified by pressing the A button, then the change will persist when loadLevel is called again. again, click on that image to try it out
2 Likes