finish and unfinish - ThePix/QuestJS GitHub Wiki

Use io.finish() to end the game.

Quest will continue to run the function that called io.finish(), but then everything will stop. No turn scripts will run, and this will not count as a turn passing as the world will not be updated. If you want this to count as a turn, just do:

  game.turnCount++
  io.finish()

You can have a script run by adding it to settings.afterFinish. This is an array, so use "push".

  settings.afterFinish.push(function() {
    player.outputScore()
  })

You can also set settings.finishMetaComment to a string that will be printed out after those functions have run. If there is a transcript running, the user will be given a link she can click to access it.

  io.finish(true)

Allowing UNDO and RESTART

If you pass true to io.finish, Quest will ask the user if she wants to undo or restart. The undo option actually does a command called UNFINISH, which calls io.unfinish. It undoes changes to the UI, but nothing else. If you have not made any changes yourself, that is fine, but if you have made changes you will need to reset them. You can do that by adding functions to settings.afterUnfinish. This example resets the turn count.

  settings.afterUnfinish.push(function() {
    game.turnCount--
  })

The restart option just calls RESTART, and is no different to the user clicking the reload button on the browser.