If you use Snowman with a lot of reusable code, or even if you build some kind of engine that runs a lot of code in every turn, there are two ways I can think of writing that reusable code.
a) You can just write Javascript functions in the Javascript passage and run them with <% somefunction() %>
b) You can put the code in its own passage, with <% code %>
, and invoke that passage whenever you need with <% story.render("some passage") %>
Is there any preferred, more optimal way to do this? As far as I can tell, there is only one difference: if you write functions in the Javascript passage, they are not in a <% %>
template, so you need to expand the s
shorthand to the full window.story.state
. Which is uglier, but not a great difference.
EDIT: another obvious different if that using functions lets you use local variables, which makes it easier to name things without worrying.
(I also guess that, when the game is running, calling a function should be more efficient than the bunch of actions that render a passage. On the other hand, it’s hard to imagine a Twine game ever having performance problems!)
Any comments? Thanks!