Twine Ver 2.1.1; Harlowe 1.2.3: Cycling link that changes text in other parts of same passage

0 votes
asked Sep 1 by hati_skoll (160 points)

Hi,

I'm completely new to twine, and I'm currently attempting to put in a cycling link which changes other text of the same passage. I've tried searching the forums for a solution, but I wasn't able to find one. What I currently have is a separate passage for my cycling link, which I'm displaying in my story passage. This is the cycling link I'm using:

{(set: $Vdialogue to (a: "Good morning, think you have time for an old friend?", "Been a while, still serving time in this shithole?", "Are you honestly handing that dough out free-of-charge, you could be rolling in a lot of money."))
"(link-repeat: "[(print: $Vdialogue's 1st)]<Vdialogue|")[(replace: ?Vdialogue)[(set: $Vdialogue to (rotated: -1, ...$Vdialogue))(print: $Vdialogue's 1st)]]"
}

And in the passage where my story goes, I have multiple instances of text like this one:

(live: 0.1s)
[(if: $Vdialogue is "Good morning, think you have time for an old friend?")["I think my morning just took a turn for the worse."]
(else-if: $Vdialogue is "Been a while, still serving time in this shithole?")["Piss off."]
(else-if: $Vdialogue is "Are you honestly handing that dough out free-of-charge, you could be rolling in a lot of money.")["Yes, they’re free. Do feel free to choke on a cookie."]]

Clearly I'm doing something wrong, because the text isn't appearing - the cycling link is, all the other text that's supposed to change according to the cycling link isn't. I'm trying to put in 2 cycling links, each changing 3 different parts of the same passage.

Thank you in advance for the help!

1 Answer

+1 vote
answered Sep 1 by greyelf (43,790 points)
selected Sep 2 by hati_skoll
 
Best answer

1. The first issue with your example is that the (if:) related macros within the (live:) macro's body are testing if the $Vdialogue variables is equal to a particular String value but that variable contains an Array of String values. This means that each of those conditions will never be true because a String does not equal an Array.

You could change those (if:) related macros to compare the String value against $Vdialogue's 1st instead.

2. The second issue is that the timer handler created by the (live:) macro interrupts / interferes with the user's ability to interact with the page, thus in your case the user only has the 1/10 of a second delay between each firing of the related timer event to to actually click on the page. The more of these short delay based (live:) timers you have the less time the user has to interact with the page.

Timers are generally not the best way to update a page when those updates require the user to first interact with the page to cause the update to occur. This (if:) related macros would be better placed withing the associated body of the (link-repeat:) macro, and if the same (if:) macro's need to be used in multiple places then they could be placed withing a Passage that is referenced within the (link-repeat:) macro body via a (display:) macro.

3. You are first creating a new Array object each time you use the (rotated:) macro, and then assigning a clone of that new Array object to the $Vdialogue variable, and neither of these operations are cheap.

I would suggest using an Integer based variable to track the index of which of the Array elements to display instead, as an added bonus you could check the index value within the (if:) related macros instead of a String and the comparing of two numbers is faster than the comparing of two Strings especially when one of those String's needs to be retrieved from an Array before it can be compared.

Ex 1. Still using the (rotated:) macro.

{
(set: $Vdialogue to (a: "Good morning, think you have time for an old friend?", "Been a while, still serving time in this shithole?", "Are you honestly handing that dough out free-of-charge, you could be rolling in a lot of money."))

&quot;(link-repeat: "[(print: $Vdialogue's 1st)]<Vdialogue|")[{
	(set: $Vdialogue to (rotated: -1, ...$Vdialogue))\
	(replace: ?Vdialogue)[(print: $Vdialogue's 1st)]\
	(if: $Vdialogue's 1st is "Good morning, think you have time for an old friend?")[
		(replace: ?output)["I think my morning just took a turn for the worse."]
	]
	(else-if: $Vdialogue's 1st is "Been a while, still serving time in this shithole?")[
		(replace: ?output)["Piss off."]
	]
	(else-if: $Vdialogue's 1st is "Are you honestly handing that dough out free-of-charge, you could be rolling in a lot of money.")[
		(replace: ?output)["Yes, they’re free. Do feel free to choke on a cookie."]
	]
}]&quot;
}
[]<output|

Ex 2. Using an integer index variable.

{
(set: $Vdialogue to (a: "Good morning, think you have time for an old friend?", "Been a while, still serving time in this shithole?", "Are you honestly handing that dough out free-of-charge, you could be rolling in a lot of money."))

(set: $comments to (a: "I think my morning just took a turn for the worse.", "Piss off.", "Yes, they’re free. Do feel free to choke on a cookie."))

(set: $index to 1)

&quot;(link-repeat: "[(print: $Vdialogue's ($index))]<Vdialogue|")[{
	(set: $index to it + 1)
	(if: $index > $Vdialogue's length)[(set: $index to 1)]
	(replace: ?Vdialogue)[(print: $Vdialogue's ($index))]
	(replace: ?output)[(print: $comments's ($index))]
}]&quot;
}
[(print: $comments's ($index))]<output|

 

commented Sep 2 by hati_skoll (160 points)
Thank you so much for the explanation! It was incredibly illuminating, and entirely comprehensible for an utter novice. Sending good karma your way!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...