SugarCube 2.0: Engine API
In SugarCube, the <a href="http://www.motoslave.net/sugarcube/2/docs/api-engine.html">Engine</a> API gives easy access to the history of passages and what is currently going on in the "engine" of the story.
[[What is the engine doing?]]What is the current status of the Engine: <<print Engine.state >>
Are we idle? <<print Engine.isIdle() >>
Are we playing? <<print Engine.isPlaying() >>
Are we rendering? <<print Engine.isRendering() >>
[[And timetravel. Is it possible?]]Through using {{{Engine.backward()}}} and {{{Engine.forward()}}}, we can move through the history of the story, undoing and re-doing "moments" (turns) as recorded by the engine.
<<button "Let's go back a passage!">>
<<script>>
Engine.backward();
<</script>>
<</button>>
[[Offsets and indexes]]We can even rewind a number of turns or return to a moment previously in the history through using {{{Engine.go(offset)}}} and {{{Engine.goTo(index)}}}.
<<button "Let's to return to the beginning AND save our navigation history!">>
<<script>>
Engine.goTo(0);
<</script>>
<</button>>
[[Erase everything and restart]]We can also show (play) a moment through using {{{Engine.play(passageTitle [, noHistory])}}} and supplying the name of a passage in the story and if we want it added to the history or not. And, finally, if we really want, although it is not recommended, we can restart everything with {{{Engine.restart()}}}.
<<button "Let's restart everything AND erase our history!">>
<<script>>
Engine.restart();
<</script>>
<</button>>