+1 vote
by (2.2k points)
closed by

Using Twine2, trying to get an if statement to tell whether one passage has been visited or not but I'm getting errors, what am I doing wrong? 

(if: (history: "Let's go gambling!"))[Well, that's kind of your fault for gambling the night away, isn't it?]
(else:)[I wonder why? Maybe in another life you gambled the night away and now I'm having flash backs to that life and I can't seem to get things straight. Sorry, my bad.]

Thank you

closed with the note: answered

1 Answer

+2 votes
by (159k points)
selected by
 
Best answer

WARNING: I strongly suggest not using punctuation characters within the names of your Passages, as strange things can happen when you do. So I would rename your existing Let's go gambling! passage to something like Lets go gambling and then using a link like the following to access it.

[[Let's go gambling!->Lets go gambling]]

 

The (history:) macro returns an Array, and the Array data section of the guide explains how to use the contains operator to determine if a particular value is contained within the array.

(if: (history:) contains "Lets go gambling")[Well, that's kind of your fault for gambling the night away, isn't it?]\
(else:)[I wonder why? Maybe in another life you gambled the night away and now I'm having flash backs to that life and I can't seem to get things straight. Sorry, my bad.]

note: I made two addition changes to the above example:
a. I replaced the passage name being looked for with one without punctuation characters.
b. I added Escaped line break markup between the end of the (if:) and the start of the (else:) to suppress the unwanted line-break that was appearing if the (else:) related text was shown.

by (2.2k points)
edited by
I did the changes you did but it says that it is an 'unexpected string' and has 'nothing before this (else:)'
by (2.2k points)
Never mind, I figured out how to use contains correctly. Thank you so much for your help!
...