Workshop › Sokoban › Step 23 of 29
One careless push can make a level impossible, so we will add undo. First, snapshot() turns everything a move can
change into one piece of text: a photo of the game. history will keep the photos.
```js
let history
history = []
function snapshot() {
return JSON.stringify({ player, boxes, moves })
}
```history is the list of photos, emptied on every load.{ player, boxes, moves } is an object with the three things a move can change.JSON.stringify turns it into text: a real copy. Storing the boxes array itself would store the same array, and
the next push would change the "saved" copy too.let moves write let history.loadLevel, under moves = 0, write history = [].function move, write snapshot. Press Run.Skills: Game states
← Count the moves A photo before every move →