I am trying to create a story that simply randomises a series of passages I have written.
Currently I am using the either function to link to random passages: [[>|either("P2","P3")]]
This is working well, however, a problem arises when the reader revisits the same passage several times and I only want them to view each passage once.
I played around with the visited() function but it became a little too confusing.
There is probably a very simple answer, and I would enjoy it thoroughly if you could share it with me!
If you are using SugarCube then you could store the list of possible passage names within an array $variable and then use the pluck function (2.x or 1.x) which will randomly give you the next passage name while at the same time removing that passage name from the list.
A couple of notes on greyelf's SugarCube solution:
Example Setup (should be done only once):
Example: Disabling the link
This will link to the plucked passage if $next is defined, otherwise the link will be disabled.
Example: Linking to a default passage
This will link to the plucked passage if $list.pluck() returns one, otherwise to the specified default passage.
Example: Reusing the last passage title
This will link to the plucked passage if $plucked is defined, otherwise to the last successfully plucked passage.
I tried defining $list in the StoryInit passage and then plugging in the following code into the Start passage:
<<set $next to $list.pluck()>>
<<link "Next" $next>>
But it returns an error saying that link is not a macro or passage.
To make what you tried work in Sugarcane, use the following:
For the "Reusing the last passage title" example:
Thanks a ton for handling a future question.
I tried the example you gave relating to disabling the link. It works the best of anything so far, however there is a click-able next link highlighted in red on the final passage. I think I understand what is going on, I just don't know how to fix it.
Thanks again for all of your help.
If your are sure that the passage does exist, then check that the target passage of the link is spelt exactly the same as the title of the actually passage, the case of each letter is import.
Thanks Greyelf, the problem is that the passages are defined in the array at the start of the story and then used throughout, but once the array is exhausted the red highlighted text appears. I just want to know how to remove that instance.
The start passage:
Finally, at the end of each passage:
Everything works, except at the end there is the false red link.
Changing your end of passage code to something like the following should work:
Though, if you're going to be appending that to most passages, then you'd probably be better served by making a pseudo-macro out of it. And, perhaps, calling that from a postrender task.
Thanks again for putting up with my antics