Hello all. I was wondering how I would reference the previous() function while working in javascript to get me the title of the second to last played passage. I could not find anything in the docs to accomplish this, but may have missed it.
As long as the javascript in question is running inside SugarCube’s scope — i.e. in a <<run>> or <<script>> macro, or in the story’s Javascript section — then you can use it exactly as is.
e.g.
<<set _temp to previous()>>
If you try to access it from something outside that scope, such as a normal <script> element, either in the document head, or in a passage, or in a module loaded using loadScripts(), or in the browser console, you will not be able to access it.
I’m using the global Config.navigation.override function in javascript and checking for a certain passage last visited to trigger a redirect. Hmmm seems like there has to be some way to do it. I could check for the conditions on passageReady using previous(), but that would prevent the back button from being usable once the conditions are met which is generally not ideal or recommended.
At the time Config.navigation.override is called, passage navigation has not yet happened. This means that the passage you are leaving is passage() and previous() is actually the passage before that. Could that be your issue?