0 votes
by (200 points)

I'm using Sugarcube 2.21.0 and I'm trying to create a link that displays text but can also be clicked repeatedly.

<<link>> can be clicked repeatedly, but it doesn't display any text, instead operating silently.

<<linkreplace>> prints text, but it can only be clicked once.

I'm building an RPG and the goal is to create a <<link>> that allows the player to watch TV, which will output some random text about a show. However the player should also be able to click the link multiple times so as to watch multiple "episodes" in the same sitting.

This is a simplified example of the code I have so far:

<<linkreplace "Watch TV show">>
You watch 
<<switch random(1, 2)>>
<<case 1>> 
a warrior battling a dragon.
<<case 2>> 
a wizard wandering the lands.
<</switch>>
<</linkreplace>>

So right now when "Watch TV show" is clicked, the link disappears and it prints a random episode made up of the strings in the switch statement. But what should happen is that the "Watch TV show" link should stay active so the player can click it again to generate another random episode.

I've written a version of the code in Harlowe , using the (link-repeat) function, that does pretty much exactly what I need:

(link-repeat: "Watch TV show")
[(print: "You watch ")
(set: $output to (random: 1, 2))
(if: $output is 1)[(print: "a warrior battling a dragon. ")]
(elseif: $output is 2)[(print: " a wizard wandering the lands. ")]] 

This was really simple and took me about 5 minutes to do, even though I don't understand Harlowe or use it regularly. The problem is that the program I need it for is written entirely in Sugarcube. Surely it's possible to do the same thing in Sugarcube?


Sorry if this is a really simple question. I've Googled everything relating to this for like half a day but can't find anything. Thanks in advance.

1 Answer

+1 vote
by (44.7k points)
selected by
 
Best answer

This question is answered over at r/twinegames.

by (200 points)
Thanks! Here is the link to the thread: https://www.reddit.com/r/twinegames/comments/bwegmg/sugarcube_is_there_a_link_that_prints_text_and/

I can't log in to my reddit account for some reason, but I appreciate your answer.
This site has been placed in read-only mode. Please use the Interactive Fiction Community Forum instead.
...