I feel like this is an easy one, but it has been boggling my mind for too long…
I’m trying to get different text to display when entering this passage more than once. Currently, the passage only displays the first portion of text and doesn’t show the elseif regardless of how many times I enter the passage.
The main issue is that if the player keeps entering this passage, the “glasses” stack up in inventory. I thought providing an elseif statement would fix this since it wouldn’t read the $bag.push(“glasses”) if the passage was entered a second time, but now my elseif doesn’t appear regardless of how many times I enter the passage.
<<if hasVisited("Examine Family Portrait")>>You reach for your glasses and slide them onto your face.
[[Put down the family portrait|nightstand]]
<<silently>><<set $bag.push("glasses")>><</silently>>
<<elseif hasVisited("Examine Family Portrait")gte 2>>A lump grows in your throat as you look at the photo.
[[Take the photo|Simon's room]]
<<silently>><<set $bag.push("family portrait")>><</silently>>
<</if>>
I have also tried:
<<if hasVisited("Examine Family Portrait")eq 1>>You reach for your glasses...
So that it would somewhat match the gte in the following statement, but it still only displays the first section of text and not the elseif.
____
An additional question - I thought that if you were checking the current passage with hasVisited you didn’t need to add the passage name in the parenthesis. For example:
<<if hasVisited()>>You reach for your glasses.
But when trying this, I kept getting Error: <>: bad conditional expression in <> clause: hasVisited called with insufficient parameters. The error resolved when adding the passage name, but I could’ve sworn leaving it blank for the current passage had worked for me in the past. Am I mistaken or have I just left out a piece?
That isn’t how hasVisited() works. It returns true if the passage has been visited and false if it hasn’t. It does not keep a count of the number of times you have visited the passage.
I think that visited() is more what you’re looking for. Or you could keep track yourself with something like <<set examinedPortrait +=1 >> at the beginning of the passage.
If you are wrapping that line in the <<silently>> macro to suppress any visual output and/or line break it might generated then:
the <<set>> macro itself doesn’t directly generate visual output.
the line-break at the end of that line, directly after the macro call’s <</silently>> end-tag, is what’s causing a HTML <br> element to be added to the generated output.
SugarCube includes many nobr related techniques that can be used to suppress line-breaks in the Passage content being automatically converted into HTML <br> elements. In this specific case Line Continuation markup might be useful.
eg. replace this line…
Here is the updated passage (also included @Greyelf 's <<set>> changes). It’s now returning this error Error: <>: bad conditional expression in <> clause: Visited is not defined, but isn’t it defined by “Examine Family Portrait”? I’ve also tried to leave the parentheses blank, but it gave me the same error.
<<if Visited("Examine Family Portrait") == 1>>You reach for your glasses and slide them onto your face, the image before you emerges from the blur.
[[Put down the family portrait |nightstand]]
<<set $bag.push("glasses")>>\
<<elseif Visited("Examine Family Portrait") >= 2>>A lump grows in your throat as you look at the photo. Your mind wanders to what life would be like if the world hadn't ended that day.
[[Take the photo|Simon's room]]
<<set $bag.push("family portrait")>>\
<</if>>
Thanks for the comments! I appreciate yalls insight on this~