Workshop › Zelda-style Dungeon › Step 16 of 22
Leave the room and come back: the heart is there again, because enter loads the room fresh. The world must remember
what was taken. Every taken tile gets a name like '0,0,11,7' (room and tile), kept in a Set; enter turns those
tiles into floor.
```js
let taken // what has been picked up or opened in each room, so it stays that way
taken = new Set()
// Load a room: its tiles (minus what was already taken), and fresh enemies on its e tiles.
function enter(rx, ry) {
room = { rx, ry }
tiles = ROOMS[ry][rx].map((line, row) =>
[...line].map((ch, col) => (taken.has(rx + ',' + ry + ',' + col + ',' + row) ? '.' : ch === 'P' || ch === 'e' ? '.' : ch)),
)
const id = room.rx + ',' + room.ry + ',' + col + ',' + row
taken.add(id)
```Set is a collection without repeats; has asks if a name is in it, add puts one in.enter now needs row and col too, to build each tile's name.tiles, write taken; at the top of reset, make it a new Set.tiles line of enter to skip taken tiles, and write the comment above enter.update, name the tile under the hero, and remember it when something is picked up.Skills: Game states, Arrays and objects
← Keys and hearts The locked door →