Twine 1.4 and SugarCube 2.
Let's say I have a simple passage like this:
Some text and <<click "button">><</click>>.
When the button is clicked I want to: get a random passage from a list, then get a random sentence from that passage, and display it below the original text and button--with any links removed/deactivated (so only showing plain text sentence). So the player can keep clicking the button, and new random sentences will keep appearing below it.
I know I can display a random passage with:
<<set $passage to either("Passage 1", "Passage 2", "Passage 3")>>
<<display $passage>>
And I
thought I could display a random passage on button click with something like this:
<<click "Show Random">><<set $passage to either("Passage 1", "Passage 2", "Passage 3")>><<display $passage>><</click>>
But that's not working.
As for grabbing a random sentence from the passage (rather than displaying the whole passage), and deactivating the links... I assume this is something I should try to do in prerender, via some kind of black magic vaguely
like this?
Comments
That's an excellent question. Ideally, I would like to grab text from normal passages (i.e. actual game passages that the player has been traveling through)... but now that you mention it, I could probably get most of the way to the effect I want by manually creating an array of twenty or thirty sentences taken from various passages... (which I assume would enable a much easier solution, which would probably be worth the trade).
If reusing a sentence isn't an issue, then you could simply do something like the following.
Goes in a widget-tagged passage: Usage: To add <<click>> to the mix, you'd want something like the following:
If you don't want to possibly reuse a sentence, then the following should probably suffice.
Goes in the StoryInit special passage: Usage: To add <<click>> to the mix, you'd want something like the following:
On the other hand, if you prefer to use an array of sentences, you can use them in the corresponding passages to keep synchronization, i.e.
::passage N
...
<<$sentences[N]>>
...
instead of actual sentence. So. this will do what you want, only from the other end
Just curious, why do you need such a tricky thing as a random sentence from a random passage in you story?