Complex If Statements

Hi, first time im attempting to do something like this, I’m using twine 2 and Harlowe, the latest versions downloaded from

I want have a system where a passage is displayed depending on the value of a variable. I’m encountering the problem that the if and else-if statements seem to stop after processing only a few lines. This is what it looks like now:

(if: $time <= 3)[(go-to: “passage1”)]
(else-if: $time = 4)[(go-to: “passage2”)]
(else-if: $time <= 7)[(go-to: “passage3”)]
(else-if: $time = 8)[(go-to: “passage4”)]
(else-if: $time <= 11)[(go-to: “passage5”)]
(else-if: $time = 12)[(go-to: “passage6”)]
(else-if: $time <= 15)[(go-to: “passage7”)]
(else-if: $time = 16)[(go-to: “passage8”)]
(else-if: $time <= 19)[(go-to: “passage9”)]
(else-if: $time = 20)[(go-to: “passage10”)]
(else-if: $time <= 23)[(go-to: “passage11”)]

(else: [(go-to “Start”)])

How can I get the different passages to display depending on the number value of the $time variable?

Thank you

Please use the toolbar’s Preformatted Text option when supplying a code example, it makes then easier to read and cut-n-paste.

warning: The String values (like “passage1”) within your code example are delimited with invalid typographical (curly) double quotes, when they should be delimited with either standard single or double quotes (eg. 'passage' or "passage"). I don’t know if the typographical (curly) double quotes are a result of the way you added the example to your question (without using the Preformatted Text option) or in your actual code of your Twine project, if the later then you will need to replace them with standard ones.

There are three issues with your code example:
1: Your (else:) macro call is malformed, the associated hook has been place where a macro argument would appear if that specific macro supported such.

  1. The (go-to:) macro within your (else:) macro’s associated hook is missing a colon after the macro name.

3: You are using a single equal sign (=) operator within the conditional expression of some of your (else-if:) macro calls and in JavaScript (and similar programming languages) a single equals sign is used to indicate ‘assignment’, not comparison.

Generally you would use either a triple (===) or double (==) equal signs operator when doing a comparison, however neither of those operators are listed in the Boolean data section of the Harlowe manual and usage of such doesn’t always work as expected.

The following copy of your original example contains fixes of the above mentioned issues, I have also added formatting to it to make it a little easier to read, which can also help with spoting syntax errors.

(if: $time <= 3)[
	(go-to: "passage1")
(else-if: $time is 4)[
	(go-to: "passage2")
(else-if: $time <= 7)[
	(go-to: "passage3")
(else-if: $time is 8)[
	(go-to: "passage4")
(else-if: $time <= 11)[
	(go-to: "passage5")
(else-if: $time is 12)[
	(go-to: "passage6")
(else-if: $time <= 15)[
	(go-to: "passage7")
(else-if: $time is 16)[
	(go-to: "passage8")
(else-if: $time <= 19)[
	(go-to: "passage9")
(else-if: $time is 20)[
	(go-to: "passage10")
(else-if: $time <= 23)[
	(go-to: "passage11")
	(go-to: "Start")
1 Like

That worked, thank you so much for your help :slight_smile: