+1 vote
by (550 points)
I'm looking at the Sugarcube API and there seems to be a State object that handles the history of the game. This is great, but I'm not really sure how I'm supposed to access it. The documentation doesn't really make it clear... maybe I'm just missing something.

Harlowe had the (history:) macro, and I could do things like: last of (history).

 

How do I access the 'State' object in Sugarcube?

2 Answers

+1 vote
by (63.1k points)
The engine API has functions for traversing the whole history, specifically of interest is Engine.goTo() and Engine.go(). If you're only trying to go back one passage, though, you should generally use either the previous() function or the macros <<previous>> or <<back>>. Note that these macros are similar but not exactly the same. Specifically, <<previous>> goes to the last passage but pushes the history forward, meaning it doesn't undo changes to variables and such, while <<back>> pushes the entire state history back.
by (550 points)
This is a good answer, and will probably be good for my future endeavors, but it doesn't really answer the question.
+1 vote
by (159k points)

The API sections (eg. Dialog, Save, State, etc...)  describe Javascript objects and functions that you can use to access core parts of the SugarCube engine. There are a number of ways you can use these objects/functions depending on exactly what you are trying to do, some of these ways include.

1. Inside custom macros, like those created using the information found in the Macro API section.

2. Within <<script>> macros.

3. Within <<set>> macros.

4. Within your own custom Javascript code.

5. From within the Console of your web-browsers built in Development Tools.

by (550 points)
This is a decent answer. I'll have to go through the links to see exactly how to use these things and if they have the info I'm looking for.
...