0 votes
by (2k points)
edited by
I'm trying to use an inventory system and my next goal is to get the reader to click on a link that shows a text over my previous text (I use a textboxt, so my space is limited) and then, when I click on the link again, it dissappears and shows the previous text. Idk if it would be usefull to put the code for my textbox here.

1 Answer

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

You could create a widget to do this. Create a new passage, give it the tag "widget" then enter something like the following:

<<widget "mylink">><<nobr>>

<<capture $args[0], $args[1]>>
<<linkreplace "$args[0]">>
	<<mylink $args[1] $args[0]>>
<</linkreplace>>
<</capture>>

<</nobr>><</widget>>

Then call it like this:

<<mylink "your initial text" "the text you want your link to turn into">>

 

by (2k points)
Oh, I see, and if I want to create more widgets later on should I put them in the same passage or create another one?
by (23.6k points)
You can put them into the same passage or create a new one - whatever is best to keep everything well organized for you.
by (44.7k points)
You can also add a "nobr" tag to your widget passage(s), if you don't want to have to use the <<nobr>> macro in all of your widgets.
by (68.6k points)

The example given in idling's answer, as I write this, has a few issues.

  1. The <<capture>> invocation is not doing what they think it is.  The <<capture>> macro captures story and temporary variables, not properties/indices.  Thus the following from idling's example:
    <<capture $args[0], $args[1]>>

    Is equivalent to:

    <<capture $args>>

    In other words, it's capturing the entire $args special variable, rather than simply the first two indices.

  2. The quotes around the argument to <<linkreplace>> are erroneous and should not be there.  There are very few instances where you need to quote a variable being used as an argument to a macro and they're documented.  This is not one of those instances.

  3. Since this is supposed to allow two chunks of text to be swapped back and forth, I'd recommend against using any of the no-break features, since they all convert line breaks to spaces.  Line continuations are a better fit in cases where you want the line breaks to be completely removed.

For example, I'd suggest something like the following:

<<widget "mylink">>
	\<<capture $args>>
		\<<linkreplace $args[0]>>
			\<<mylink $args[1] $args[0]>>
		\<</linkreplace>>
	\<</capture>>
\<</widget>>

PS: Beyond those obvious issues, the construct will also insert a new element each time the player clicks on the link, which is less than ideal but should be livable in this case.

...