Tracking coins picked when killed in a level

Hi,
I am using placeholders on tilemap to set initial position of coins/gems in the level. These placeholders are replaced with blank tiles when coin sprites are created. These coin sprites are destroyed when player overlaps. When the player is killed in the level and the level gets reloaded; is there a simpler way to track which coins were picked up and which needs to be placed again - i can think of using arrays to keep track but sounds like overkill.
Any suggestions???
Plz help!!!
warm regards
MINTGenie

If you use the tilemaps extension, then you can cover the tile when the coin is spawned instead of setting the underlying tile, then set it to be the background only when the player overlaps with it. That way you don’t clear all of the coins when reloading the level.

If you want to try arrays, I’d keep an array of locations and then check to see if the location is in the array when the level is loaded and not spawn them in that case, then clear the array when the level is completed. You might need to use the tilemaps extension for checking if it is in the array, because you need to get the column and row to compare two locations. Regular == won’t work.

1 Like

So is it generally bad to reload the tilemap when reloading levels? I am reloading the tilemap - this might be causing all the trouble.

No, it’s fine! Just keep in mind that changes to the tilemap will persist even if it’s reloaded. If you want to avoid that behavior, you can use the “copy” block in the tilemap extension to make a clone of the map before you load it.

1 Like

I went down the “destroy & recreate” rabbit hole becoz the animations were not stopping. Now that the animation of seaweeds is fixed, I removed all the destroy-world code whenever player loses a life and recreate only the player. This seems to be working smoothly. Thanks for the hints.
Here is the latest: https://makecode.com/_9apf6y22Vd7m
Thanks again