Creating a drop-down linking to specific story passages

Twine Version: 2
Story Format: Harlowe

I am still working on my Twine pub quiz. I ran the first one yesterday and it worked fairly well, but there are a few kinks to iron out!

First thing is to create a drop down menu which links players to a given question (aka passage).

I have currently got:

(dropdown: bind $q, “q1”, “q2”, “q3” \and so on up to\ “q60”)

(live: 5s)[
(if: $q is “q1”)[(go-to: “Question 1”)]
(if: $q is “q2”)[(go-to: “Question 2”)]
(if: $q is “q3”)[(go-to: “Question 3”)]
(if: $q is “q3”)[(go-to: “Question 3”)]

This solution DOES work, just about, but the page momentarily refreshes every five seconds and there is a brief delay after the player selects the question they want to go to. Is there a better way to do this without having to constantly “refresh” the menu?

Actually the solution doesn’t work as every time the menu refreshes the variable is reset meaning that the user is sent back to question 1 every five seconds.

Aha, I’ve found a way to do it:

Select question:
(dropdown: bind $q, “q1”, etc etc)

{(click: “Go!”)[
(if: $q is “q1”)[(go-to: “Question 1”)]
(if: $q is “q2”)[(go-to: “Question 2”)]
etc etc ]}

Please use the Preformatted text option in the toolbar when including code examples.

warning: Due to how the (click:) family of macros are implemented it is generally recommended that you use one of the (link:) family of macros instead when ever possible. You should also initialise the bound variable in case the end-user doesn’t select an option before clicking on the link. So your solution would be better implemented like so…

Select question:
(set: $q to "q1")\
(dropdown: bind $q, "q1", "q2")

(link: "Go!")[
	(if: $q is "q1")[(go-to: "Question 1")]
	(else-if: $q is "q2")[(go-to: "Question 2")]
	(else-if: $q is "q3")[(go-to: "Question 3")]

You will notice that I have replace the 2nd and later of your (if:) macro calls with (else-if:) macros, I did this because you want those later conditions not to be checked if an earlier one is true. This use-case is used when the conditions are Mutually Exclusive, as in only one condition can be true at any one time.

1 Like

Hi Greyelf,

Thanks for the very helpful response. I have made some more updates to my online pub quiz (including the ones you recommended) and am looking forwarded to test driving it again this evening!