Moving to new section after showing some text

I want to move from 2 possible sections to a common third section, but I'm having some trouble. Here's my attempt:

[[section 1]]:

    squiffy.story.go("section 3");

Some text

[[section 2]]:

    squiffy.story.go("section 3");

Some text

[[section 3]]:

more text

But it won't display the text from sections 1 or 2 before going to the section 3. Is there a way to do it without needing user input?
My expected result is:

Some text
more text


Why not just:

[[section 1]]:

Some text
{section 3}

[[section 2]]:

Some text
{Section 3}

[[section 3]]:

more text

?

Unless section 3 contains passages, in which case I think you need something like (top of my head):

[[section 1]]:
    squiffy.ui.write(squiffy.story.section.text);
    squiffy.story.go("section 3");

Some text

[[section 2]]:
    squiffy.ui.write(squiffy.story.section.text);
    squiffy.story.go("section 3");

Some text

[[section 3]]:

more text

to force the text to be written first.


Thank you very much. That's exactly what I wanted to do. The documentation doesn't show that we can move to a section by using "{}". Perhaps, it would be a good addition for newbies like me.


Using {} doesn't actually move to another section. It just includes the contents of that section's text. Although the difference is only apparent if you click a passage link (you are still in section 1 or 2), if section 3 contains javascript (which won't run), or if you later use {if seen section 3: (which will be false).


I just noticed it the hard way. Some links aren't working properly and the variables aren't incrementing as I expected. I think I will have to use the second approach you recommended and alter the variables using javascript as well. Looks a bit messy to me, but looks like the only option. Is that right?


alter the variables using javascript as well

I don't think you should need to do anything fancy with the JS.

The sequence when you go to a section (whether by clicking a link or squiffy.story.go) is:

  1. setSeen - I thought this was at the end; must have been thinking of Quest gamebooks
  2. squiffy.story.run
    1. @clear
    2. All other @ attributes
    3. Run JS
  3. If the _section attribute hasn't changed
    1. squiffy.ui.write(squiffy.story.section.text) - display the section's text.
    2. Save
    • (The if clause is so that if the JS moved us to another section, we don't display the text for this one)

In this case, you're doing the write manually to display the text before moving; but attribute changes for the first section will already have happened, and in the second section will happen as normal.

Unless you want the variable changes in section 3 to be usable in the text of the earlier ones, in which case you could do something like:

[[Section 1]]:
    squiffy.set("_section", "section 3");
    var nextsection = squiffy.story.sections["section 3"];
    squiffy.story.run(nextsection);
    squiffy.ui.write(squiffy.story.section);
    squiffy.ui.write(nextsection);
    squiffy.story.section = nextsection;
    squiffy.story.save();

Some text here…

(Off the top of my head)


Log in to post a reply.

Support

Forums