0 votes
by (120 points)
I am trying to create a branching narative and had planned to link to one of two cards to the original depending on a boolean. As example:

(set: $Bool to true)

(if: $Bool is true)  [[Click Button->Page1]]  (elseif: $Bool is false) [[Click Button->Page2]]

I want to be able to place one of the two links into the same line dependant on the bool state but dont know how to make that work exactly being new to twine. Any help would be appreciated.

1 Answer

0 votes
by (149k points)

note: When you say 'card' I will assume you actually meant 'Passage'. I will also assume that you know that the initialisation of your $Bool story variable needs to occur sometime prior to the displaying of the passage that includes your (if:) related macros, ideally that would be within your projects startup tagged special passage.

There are three issues with your example, the 1st is what is causing it not to work as you want, and the 2nd & 3rd are syntax / logic errors.

1. Your (if:) related macros are missing their associated hooks. (the [ ] part)

2. A Boolean can only equal one of two values (true or false) so you should be using an (else:) macro instead of the (elseif:) macro.

3. You shouldn't use is true or is false when checking if something equals to Boolean true or false, the correct way to do that is by either checking the variable's value directly in the case of true, or by using the not operator in the case of false.

(if: $variable)[This will only appear if the variable equals true]

(if: not $variable)[This will only appear if the variable equals false]


So based on the above three points your original (if:) related example would look something like the following...

(if: $Bool)[[[Click Button->Page1]]]\
(else:)[[[Click Button->Page2]]]

note: I used Escaped line break markup in my last example to make it more readable, you can safely remove both the back-slash character and the line-break that follows it if you perfer the (if:) & (else:) macros to appear on the same line in your passage content.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...