SugarCube 2.0: State API
While functionality like the <a href="http://www.motoslave.net/sugarcube/2/docs/api-engine.html">Engine</a> or <a href="http://www.motoslave.net/sugarcube/2/docs/api-story.html">Story</a> API give access to what the "engine" is doing (status or at a moment in the history of the story) and with Story, information about its passages and itself can be retrieved, there is also the <a href="http://www.motoslave.net/sugarcube/2/docs/api-state.html">State</a> API.
[[All about the current]]The State API gives access to everything about the current moment.
Is our history empty? <<print State.isEmpty() >>
What is the current passage's name? <<print State.current.title >>
What was the last passage's name? <<print State.bottom.title >>
How many moments have passed so far? <<print State.length >>
[[Variables!]]
<<set $someVar1 to "See?">>
<<set $someVar2 to "A Value">>
<<set _anotherVar to "Temp!">>
Like with details about the current moment, we can also retrieve information about the current and temporary variables.
What's the value of "someVar1"? <<print State.variables.someVar1 >>
What's the value of "someVar2"? <<print State.variables.someVar2 >>
How about temporary "anotherVar"? <<print State.temporary.anotherVar>>
[[Random]]Finally, beyond history and variables, State also gives access to the pseudo-random number generator (PRNG) functions {{{State.initPRNG()}}} and {{{State.random()}}}.
(Unless {{{State.initPRNG()}}} is called, {{{State.random()}}} will use the built-in {{{Math.random()}}}. And why use State's random, then? It's more random -- and more predictable at the same time.)
Math's random: <<print Math.random() >>
State's random: <<print State.random() >>