Sugarcube: Visited Passage question

I’m using SugarCube. I’m relatively new and not sure how to find which version I’m using, would love to know that for future reference.

I’m hoping to find a way to trigger something to happen if either one of two passages has been visited. (for example, I have two passages named “It’s mine” and “It’s magic” and I want something to happen later if either one of them has been visited.)

I know how to use if hasVisited to make a change if one specific passage has been visited, or if both of two passages have been visited, but I need something for if the reader has chosen either one of two.

I can clarify if this is confusing. Thanks so much!

It sounds to me you actually already have 90% of the solution. The <<if>> macro allows for more than one condition to be tested. Especially the || operator is read ‘or’, if any of the conditions separated by an ‘or’ is true, then the whole is true.

<<if hasVisited("It's mine") || hasVisited("It's magic")>> ... whatever should happen <</if>>

It is true if the reader has visited “It’s mine”, “It’s magic” or both.
However I think hasVisited() does not consider the passage has been visited if it has been called in another passage, for instance with <<include>> or <<replace>>.

1 Like

I didn’t know that about || meaning “or”! That solves my problem perfectly. I’ll update everything that wasn’t working. Thank you!

This is true. Also doesn’t count if it “popped up” via Dialog API.

Alternately I believe you can count the number of visits also:
<<if visited("It's mine") + visited("It's magic") gte 1>> [ something]

…meaning you can count number of visits to multiple passages and add them together. If neither has been visited it would evaluate to 0.

[Had to edit: hasVisited() gives you boolean true/false, where visited() evaluates to a count of passage views. Leaving brackets empty defaults to the current passage.]

1 Like