I’m new to twine and the documentation of snowman isn’t much help without corresponding examples. Right now, I’m trying to navigate from one passage to another based on certain time (example: 5 seconds). How can I achieve this?
also, are there examples on how I can use window.story to get the passage name? I tried using window.story.show(“id”) but this just prints in the passage as text.
Snowman is a minimal Twine 2 story format designed for people who already know JavaScript and CSS
…so it assumes that the Author already: has knowledge about how to use JavaScript, and experence with reading API like documentation. The official Twine Cookbook does include some Snowman based recipes.
You can use Snowman’s story.show() function to programmatically cause a Passage Transition, and JavaScript’s setTimeout() function to delay the execution of that story.show() call. A HTML<script> element may be needed if you intend to do the above within the contents of a Passage.
The following TWEE Notation based example demonstrates using the above to achieve the outcome to mentioned…
:: Start
Wait five seconds...
<script>
setTimeout(() => {
story.show('Other Passage');
}, 5000);
</script>
:: Other Passage
Welcome to the Other Passage.
If you intend to do many such delayed transitions then you may want to declare a custom function that you use instead of the above <script> wrapped code.
The following JavaScript first declares a personal Namespace to store any custom functions you may need, I call mine GE but you should use your own unique identifier. Next a custom function named delayedGoto() is added to the Namespace, which contains the code from the <script> with two arguments added. This code should be placed within your project’s Story JavaScript area.