Hello,
I'm trying to build a kind of engine where, instead of jumping from one passage to another, the game loops through the same engine passage, embedding content from other passages.
So the engine prints, through story.render, certain passages. Those passages contain option links. When you click one link, some variables are changed and the engine prints another passage.
Where's the problem? What I asked in a question posted before. When the engine passage renders the first content passage, the links inside that passage, with code inside <% ... %>, do work. But when you click on a link and a second passage is rendered, the links inside that passage don't work. For example, a link like this:
<% $(function () {
$('#id').click(function () {
s.variable="value";
$('#passage').append(story.render("main"));
});
}); %>
When you click on #id, it changes a variable and appends the engine passage ('main') to #passage. The engine, in turn, embeds other passages through story.render. This works only the first time that I call the engine. The second, it doesn't work.
I guess this is perhaps related to this Snowman feature:
> $
, which acts like jQuery's $
method but with one exception. If you pass it a single function, this function is run when the passage appears onscreen, with it bound to the passage DOM element.
The solution in the linked question was using <script> instead of <% %>. That works initially, but it seems to create other problems. For example, I added some HTML structure to the engine passage and it spat a syntax error.
I have uploaded a test to philome.la.
Do you think there is any way of working around this Snowman behaviour? Thanks!