0 votes
by (2.2k points)

Imagine following scenario: when player character dies, background music stops, special "game over" sound is played and player is given choice to restart the game or open Jump To dialog. When the player jumps back to selected bookmark, background music resumes.

I tried to implement this using PassageHeader where <<if>> checks if user visited certain passages, but apparently Jump To completely erases not only current history, but expired too, because both State.hasPlayed(passageTitle) and visited([passages…]) return false when I check for that passage where death happened. I also tried visitedTagsprevious and even using variables, just in case. 

The only solution I see now is to write flag into localStorage, but this will open a whole new can of worms. Am I missing something? Is there better, may be "think outside of the box" solution?

1 Answer

+1 vote
by (68.6k points)
selected by
 
Best answer

The Jump To menu erases nothing.  All it does is send the player back in time to the destination moment—i.e. it rolls the player back to an earlier point in the history.  The reason neither visited() nor State.hasPlayed() found the death passage at that point is because it was in the potential future history, which neither of them check.

If your goal is simply to restart your BGM, you could simply set a value on setup in the death passage—I can't really think of a reason it needs to be stateful.  For example:

<<set setup.pcDied to true>>

Then simply check for that in PassageReady or whatever—n.b. I wouldn't use PassageHeader for bookkeeping tasks like this as it generates output.

by (2.2k points)

Well, "erases" was obviously poorly chosen word, I'm sorry. I know that it rolls the player back.

simply set a value on setup in the death passage

Thanks, looks promising. Where can I read more about this setup thing? Can't find it in the docs.

I wouldn't use PassageHeader for bookkeeping tasks

Thanks for the advice, I'll definitely move music management there.

by (159k points)

 Where can I read more about this setup thing?

Information about the setup object can be found within the Special Names documentation.

by (68.6k points)

It is as greyelf says.  There's not much to the setup object's documentation, however, because there's not much to it.  It's simply a generic object, which is within SugarCube's scope but not part of the history, whose sole purpose is for authors to use as they like.

by (2.2k points)
Thanks for quick help!
...