Moving to new section after showing some text
vitorsgoncalves
09 Jul 2022, 01:54I 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
mrangel
09 Jul 2022, 10:31Why 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.
vitorsgoncalves
09 Jul 2022, 18:30Thank 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.
mrangel
09 Jul 2022, 21:47Using {}
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).
vitorsgoncalves
12 Jul 2022, 03:36I 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?
mrangel
12 Jul 2022, 12:02alter 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:
setSeen
- I thought this was at the end; must have been thinking of Quest gamebookssquiffy.story.run
@clear
- All other
@
attributes - Run JS
- If the
_section
attribute hasn't changedsquiffy.ui.write(squiffy.story.section.text)
- display the section's text.- 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)