0 votes
by (140 points)
edited by

Hello. I'm trying to add an aspect to my Twine game where the game goes to the ending if at any time a certain variable goes below 0. My understanding is to use a header passage.

I started my header with:

(if: $skill is < 0)[(goto:"Fail")]

This worked to send the game to the "Fail" passage in the event that $skill became -1 or less. However, it then endlessly completes the (goto:) because the (if:) is always true.

I am using Twine 2 with the Harlowe settings.

What do I need to do in order to make the code stop after arriving at the "Fail" passage? Thank you.

EDIT: Figured it out, though I'm not sure if it's the *right* way to do it:

(if: $skill is < 0 and $fail is 0)[(set: $fail to 1)(goto:"Fail")]


1 Answer

0 votes
by (159k points)

You simple need to modify your header code to only run if the current passage isn't the Fail passage.

The following (untested) code shows one way to do this, it  uses the (passage: ) macro to obtain information about the current Passage being shown and the (unless: ) macro to check the passage's name.

(unless: (passage:)'s name is "Fail")[
	<!-- The conditions that cause the Fail passage to be shown. -->
	(if: $skill < 0)[
		(goto: "Fail")

You shouldn't use the is operator when checking for a < ba > ba <= b, or a >= b, the reason for this is that the is operator is the equivalent of a == b (where == basically means "exactly equal to").

So when you write something like $skill is < 0 you are saying that the value of $skill must be both "exactly equal to 0" and "less than 0" at the same time, which is a contradiction and makes no sense. Harlowe was recently changed to recognize this contradiction and to ignore the is operator in these specific cases.