Hey there, I'm pretty new to twine and I had a question on whether or not it's possible to create an if-else statement that takes into account some rather complicated variables or if I should find a workaround.
From what I can tell it's not possible to include multiple if's or else's within the same if-else statement, so I thought I'd try making two different ones. At it's most basic, it looks like this:
<<if $seen_2 eq "yes">>Text description if you've seen passage 2
<<else>>Text description if you haven't seen passage 2
<<endif>>
However, I'd like to make it so that if you haven't seen passage two but have seen at least one of two other passages that it will display different text. So I tried inserting another if-else statement, but I can't seem to get any sort of 'unless' statements to work. It looks like this:
<<if $seen_4 or $seen_5 eq "yes" unless $seen_2 eq "yes">>Text description if you've read 4 or 5 but not passage 2
<<else>>Text description if you haven't read passage 2 but have seen 4 or 5
<<endif>>
If anyone knows the correct syntax to get this all to work in one passage then I would be very grateful. Otherwise I might see about getting it to lead to one other passage so I can do what I want.
Comments
The statement
has a few problems.
1. It's not checking if $seen_4 equals "yes", it's checking to see if $seen_4 is Boolean true.
2. 'Unless' isn't a valid TwineScript operator, though it is a Harlowe macro.
3. You could/should use Booleans to check for binary values instead of the string "yes". It's just generally safer and easier to understand.
So for your code, no work around is required, but it'd probably be best to change a few things.
Something like this should work if you have to use the strings:
Something like this is better:
eg. The following two complex expressions are not equal. ... because in the first example the $seen_2 neq 'yes' and $seen_4 eq 'yes' part is (generally) evaluated first, then the Boolean result of it is or'ed with the $seen_5 eq 'yes' part. And in the second example the or part is evaluated before the and
Where as the following two complex expressions are equal. ... because the part within the parenthesis is always evaluated before the part that is not.