Skip to content

MoveHistory

Undo and restart for grid puzzles, with no code: each step a grid player takes (with any crates it pushes) is a move. The UndoAction (Z, U or the gamepad’s left shoulder) puts everything back where it was before the last move, and the RestartAction (R or the left trigger) back where the level started, which Undo takes back too. One in the scene is enough: put it on the player or on the level. A Counter counting its Output “Moves” shows how many moves have been taken. With Within, it covers only part of the scene (a puzzle room in a bigger game): only steps there count, and only what’s there goes back; give each puzzle its own.

Part of the Puzzles module: Grid puzzles, Sokoban style: goals for crates (Goal), undo and restart (MoveHistory), the Puzzle template, and Create Goal in the Entity menu.

It puts back every grid mover it covers: players, crates, and chasers and patrols (where they were on their routes), each facing the way it did. Things collected or destroyed since stay gone, and the rest (counters, switches, inventories, whose turn it is) stays as it is; tick RestartReloads for a restart that starts the whole scene over. In a network game there’s no undo, and a restart starts the scene over for everyone.

Works with: GridMovement (the players, crates and enemies it puts back); Counter (counting its Moves shows how many have been taken)

Takes the player’s input only while the GridMovement it goes with has focus.

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • undoAction: text = “Undo”. The input action that takes the last move back: “Undo” is Z, U or the gamepad’s left shoulder. Empty only undoes from scripts. (Names an input action.) (Field: a name.)
  • holdToRepeat: true or false = true. Holding Undo keeps taking moves back, one after another. (Field: on or off.)
  • restartAction: text = “Restart”. The input action that starts the level over: “Restart” is R or the gamepad’s left trigger. Empty only restarts from scripts. (Names an input action.) (Field: a name.)
  • restartReloads: true or false = false. Restart reloads the scene from its file, so everything starts over (pickups, counters, scripts too), and Undo can’t take it back. Off, it puts the grid movers back where they started, as one more move Undo can take back. (Field: on or off.)
  • fade: a number = 0.3. Seconds to fade out (and back in) as a restart reloads the scene. 0 cuts straight there. (Only used when restartReloads is on.) (Field: a number.)
  • limit: a whole number = 0. The most moves it remembers, dropping the oldest. 0 remembers them all. (Field: a number.)
  • within: text = null. The part of the scene it covers, by an entity’s name: the grid movers inside that entity or standing in its area (a Room’s, a tilemap’s, a collider’s), e.g. “Puzzle Room”. Only their steps are moves, only they go back, and Undo and Restart work while a grid player with the input stands there. Empty covers the whole scene. (Names an entity.) (Field: an entity’s name.)
  • undoSound: text = null. A sound played as a move is taken back, e.g. “Sounds/undo.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • restartSound: text = null. A sound played as the level starts over. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • undoMessage: text = null. A message sent with Game.Send as a move is taken back, with the moves now taken as its data. (Names a message.) (Field: a name.)
  • restartMessage: text = null. A message sent with Game.Send as the level starts over. (Names a message.) (Field: a name.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • Undo. Takes the last move back at the start of the next frame, as pressing Undo does.
  • Restart. Starts the level over at the start of the next frame, as pressing Restart does.

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Moves (a whole number). How many moves have been taken: one more with each, one fewer with each undo, 0 after a restart.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • moves: a whole number. How many moves have been taken: one more with each, one fewer with each undo, 0 after a restart.
  • canUndo: true or false. True while there’s a move (or a restart) to take back.

Scripts use it as MoveHistory: its methods, events and values that aren’t saved with the scene.