I'd like to be able to define Javascript objects in the Story Javascript or in <<script>> tags and then have access to those objects in <<script>> tags of subsequent passages; I'm not necessarily looking to create globals, but that could work, though ideally it would be possible to do from within <<script>> tags rather than requiring the <<set>> macro. The ideal thing would be a communication mechanism that allows me to keep an object from going out of scope (or clones it into the new scope) between <<script>> tags and across passages -- is that possible?

2 Answers

Within <<script>> passages, you have access to the current state variables (via the object which variables() returns) and temporary variables (via temporary() return value). You can both read and write objects and values in there and if you use the state variables, those (or rather, deep clones of them) will persist in future passages.

If you don't need your custom Javascript Object to be persisted in the History or Save systems then I would suggest storing it on the built in setup object which is also available in all the places that you can access the story & temporary variables from.