Hi,
New to Twine, I'm using Snowman in 2.0 because I'm a heavy JavaScript programmer.
I want to to be able to store in a variable what the next passage should be, so that I can reuse a recurring passage. For example, say I want Passage A to happen periodically throughout the story. However, I want to be able to go from passage C -> passage A -> passage F or G -> A -> B or any other combination. I don't want the next passage following passage A to always be the same-- I want to keep track of what should be next in a variable.
This is my attempt, which results in an error.
In the project JavaScript:
document.twine.next_ = '';
document.twine.getNext = function() {
return document.twine.next_;
}
document.twine.setNext = function(id) {
document.twine.next_ = id;
}
In the passage I want to recur:
[[linkToNextPassage-><% document.twine.getNext() %>]]
In the passage immediately before that:
<% document.twine.setNext('test') %>
And I've created a passage named 'test'.
Why doesn't this work? Is there a way to do this differently?
Comments
Snowman allows access to it's state within underscore's <% .. %> and <%= .. %> blocks via the 's' variable, so you don't need to create your own accessor methods to store values.
The following example consists of three passages (first, second, and third) and is written using Twine notation where a line starting with a double colon indicates a new passage with the text on the same line as the double colon representing the passage's name.
Note the usage of an underscore <% .. %> block when executing a javascript expression (like the assignment of a variable) but the usage of a <%= .. %> block when outputting the result of an expression (like the value of a variable).