0 votes
by (120 points)
edited by
I'm new to Twine and coding but I'm pretty sure my code is correct, but for some reason it's not displaying. I'm making it so that if the player reached both endings, they can advance to a new path and if not they can just play again as usual. The problem is that when testing the game, I reach this point and am just met with a blank box, rather than either option. This is the only text in the box so it's not like another variable is interfering with it. Does anyone know what might be wrong?

<<if $Ruby is true && $Oscar is true>> You've found a secret path. Would you like to [[take it]]?

<<elseif $Ruby is false || $Oscar is false>> When you're ready to begin, click [[here|intro]].

<</if>>

EDIT: Problem has been solved, thank you for your help!

2 Answers

+1 vote
by (2.4k points)
Have you tried using "and" / "or" instead of "&&" / "||"? I think both of them are suposed to work, but sometimes they do weird things for me... Other thant that, the only think I can think is that $Ruby and $Oscar are not properly initialized (undefined). I'm not sure if Sugarcube reads an undefined variable as false or true...

Also, you could try using only an <<else>> instead of the <<elseif>>, since there is only one alternative to both variables being true. I think it wouldn't affect how the code works, but it would make it clearer.
+1 vote
by (159k points)

Have you initialised the $Ruby and $Oscar story variables to either true or false before visiting that Passage?

Because if you haven't then they will both default to null, which is equal to neither true or false, so both of your conditional expressions will evaluate to false. Ideally such intialisation should be done within your project's StoryInit special passage.

<<set $Ruby to false>>
<<set $Oscar to false>>


There are a couple of other issues with your example:

1. The correct way to determine if a Boolean variable is equal to true or false is as follows.

<<if $variable>>The story variable equals true.<</if>>

<<if not $variable>>The story variable equals false.<</if>>


2. You can use an <<else>> macro instead of an <<elseif>>

For your first conditional expression to successed both of the story variables have to equal true, this means that if either variable equals false then that expression will automatically fail and such a failure can be handled by the <<else>> macro. Using an <<else>> in this situation is more efficent because the values of the story variables don't have to be checked a second time, like they would need to be if you used an <<elseif>> macro.

Based on both of the above points your original example would look like either of the following.

<<if $Ruby && $Oscar>> You've found a secret path. Would you like to [[take it]]?
<<else>>When you're ready to begin, click [[here|intro]].
<</if>>

<<if $Ruby and $Oscar>> You've found a secret path. Would you like to [[take it]]?
<<else>>When you're ready to begin, click [[here|intro]].
<</if>>

 

...