0 votes
by (590 points)
hello, i'm having trouble understanding the syntax for an operation requiring the user to click some text first, then secondly have it modify a variable, and then lastly go-to a new passage.

here are some things i've tried with no success:

(click: [[link1->example link text]] ) [ (set: $variable to it +1) ]
(click: "example link text") [ (set: $variable to it +1) (go-to: link1) ]
(click: (display: "example link text") ) [ (set: $variable to it +5) (go-to: link1) ]

i understand set:, basic linking, conditional modifiers like if:, and that's about it. i don't understand hooks or any of the other stuff in the guide. i would appreciate any help that is offered in the most dumbed down explanation possible for me to grasp, thank you.

2 Answers

+2 votes
by (159k points)
edited by

The (click:) macro is used to convert either a piece of text or a named hook into something that the reader can select.

The reasons each of you three (click:) macro examples don't work is as follows:

1. The macro accepts either a String (piece of text) or a hook name as a parameter to search for in the current Passage being shown, and you are passing a markup based link [[link1->example link text]] which is neither of these two things.

2. You are correctly passing the String value of "example link text" to the macro, but that text doesn't exist anywhere else in the current Passage so the macro can't find anything to convert into a link. The (go-to:) macro is expecting a String value (text wrapped in quotes) to be passed to it and you aren't doing that.

3. The (display:) macro is used to output the contents of a Passage on the current page being generated, and this output is the wrong type of value to be passing to the (click:) macro as something to search for. Again the (go-to:) macro is being passed the wrong type of value..

The simplest way to create a link that both assigns a variable to a variable and traverse to another Passage is to use the apply named (link:) macro.

(link: "example link text")[\
	(set: $variable to it + 1)\
	(go-to: "link1")\

note: I added line-breaks and Escaped line break markup to the above example to make it more readable without adding extra lines to the page output.

by (100 points)

How about using setter-links?

* I choose the [[Garb of the Hawk][$hat = "beak"; $shoes = "talons"]]
* I choose the [[Attire of the Mire][$hat = "mud"; $shoes = "gumboots"]]


by (63.1k points)
Setter links are not supported by either version of Harlowe.
0 votes
by (590 points)
thank you for your help, it works perfectly! i'm not sure i would have figured it out otherwise.