Making modifications to tagged passages before Start

Twine Version: 2.3.2
Story Format: Sugarcube 2.28.2

\
<<set $currentlocation=passage()>>
\\

I created a special tag for my twine passages called “location” which is reserved for passages that represent physical locations in a game world. I would like to include some code (such as the code above, and probably more) to every passage with this tag.

Is there an easy way to do this during the StoryInit execution, without having to physically copy the code or an <<include “”>> statement to every single tagged passage one by one.

Do you mean displaying the location name on every passage? Or just have the variable update every time?
You could use the Passage Header/Footer or the Sidebar (if you have that) and put the code there instead (see Special Passage Name). That should update at every passage. If you only want it to update in the tagged passage, you could wrap the code you have in a conditional statement checking the tag.
<<if tags().includes('location')>>

That wasn’t the solution I was expecting, but does exactly what I need, and may help me solve some other problems I had in mind. I didn’t realize the code in the sidebar(s) re-executed every time the passage changed.

2 Likes

If you want the assigned value to be available during the passage, you should use the PassageReady special passage.

1 Like

Thanks to all who replied to this thread earlier. I’ve discovered a weird bug in my code involving

<<if tags().includes('location')>><<set $currentlocation=passage()>><</if>>

when that code is in my PassageReady passage (or really anywhere else I put this line of code that it is likely to be executed every turn.)

I’ve recreated the problem in miniature as follows

::StoryInit
<<set $currentlocation= "river's end">>

::PassageDone
<<if tags().includes(`location`)>><<set $currentlocation=passage()>><</if>>

:: newstart [location]
This is new start [[river's end]]
<<link "goto current location" $currentlocation>><</link>>

:: river's end [location]
This is river's end [[new start]]
<<link "goto current location" $currentlocation>><</link>>

When this snip is run, and “goto current location” is clicked repeatedly, it goes once to river’s end (where it was set in StoryInit) then every time after that it goes to new start, regardless of which passage it is called from.

when the <><>is removed from StoryInit, hitting “goto current location” cycles back and forth between the two locations, which is also not the way I expect it to behave.

In the larger code that this snip was culled from, I have some buttons in the right side bar that change a few variables, then call a refresh to the main screen with <<goto $currentlocation>>. The behavior is not exactly the same as in this snippet, but it sure is buggy. The reason I don’t refresh with <<goto passage()>> is that wish to refresh the most recent passage that represented a physical space in the game world, rather than expositional or transitional passages.

Moving the <<set $currentpassage>> from PassageDone to PassageReady or even to the sidebar produces slightly different results, but still buggy and unexpected…

What’s going on here, and how can I reliably refresh the most recent passage which meets the criterion defined in my tags?