How to deactivate an Option after visiting the Passage?

Hello,
I need help do make an random selctor, which deletes an Option after i visit the Passage in "Twine Sugarcube 2.31.1
That is what I got now.

<<set _psg to either(

‘passage 1’,

‘passage 2’,

‘passage 3’

)>>

<<button ‘link text’ _psg>><>

How can I delete oder deactivate an Option after I visited it.
Like I get random “Passage 2” and I use the Random Button again so there are only “Passage 1” and “Passage 3” available to get.

I hope someone understand what I mean. :sweat_smile:

The exact answer to this kind of depends on what you want to do when you run out of options.

A simple way of doing it would be to do this in your StoryInit passage:

<<set $passages = ["passage 1", "passage 2", "passage 3"]>>

Then all you’d need to do in your passage is:

<<set _psg = $passages.pluck()>>
<<if def _psg>>
	<<link "Link text" _psg>><</link>>
<<else>>
	<<link "Link text" "Default Passage">><</link>>
<</if>>

That would give you a link to the “Default Passage” passage if you run out of passages. See the .pluck() method for details.

Another, slightly better, way of doing that would be like this:

<<set _psg = [], _passages = ["passage 1", "passage 2", "passage 3"]>>
<<for _psgName range _passages>>
	<<if !hasVisited(_psgName)>><<set _psg.push(_psgName)>><</if>>
<</for>>
<<if _psg.length > 0>>
	<<set _psg = either(_psg)>>
<<else>>
	<<set _psg = "Default Passage">>
<</if>>
<<link "Link text" _psg>><</link>>

That does basically the same thing, but it doesn’t need to use a story variable or the StoryInit passage, because it uses the hasVisited() function to determine if the player has visited the passage already or not, and builds an array of only the unvisited passages.

Hope that helps! :grinning:

P.S. Any code you post here should be put inside of a “Preformatted text” marker (using the </> button), otherwise this forum tends to eat macros and the like.

Thanks, you helped me alot. :grinning:

The “hasVisited function” solved the Problem. :slightly_smiling_face:

And my next Code will be as an “Preformatted text”, sorry for that.