0 votes
by (170 points)


I am working in Harlowe 2.1.0 and am wanting to have a series of text links which the user can use to change the length of 'live'.

How can I do that?


1 Answer

+1 vote
by (159k points)

You can't change the delay of an active (live:) macro, because the internal variable that is initially assign the delay value isn't accessible once the timer associated with that macro has started.

If you explain in detail what you're using the (live:) macro to do in your story then we may be able to design a solution that allows the related delay to be changed by the Reader.

warning: Due to how the timer associated with the (live:) macro interferes with the Reader's ability to interact with the page, some care needs to be taken with both the shortness of delay length and the number of (live:) macros active at the same time.

by (170 points)
Thanks for the response. Ok, that's good to know about (live:) macro.

What I am wanting to achieve is to have the frequency of passages to be automatically displayed can change depending on how the user interacts with it - e.g. it can change between a 5 and a 10 second delay, depending on what they do?

by (159k points)

If I understand correctly you want to display the contents of a series of Passages on the current page, a little like a slideshow. The following is one way to implement such a thing.

1. The initial Passage in which the series of Passages will be shown.
It initialises a $delay variable to store the number of seconds using CSS time-units (5s and 10s in this example)

(set: $delay to 5s)

|output>[(display: "Passage 1")]

(link-repeat: "Set Delay to 5")[(set: $delay to 5s)]
(link-repeat: "Set Delay to 10")[(set: $delay to 10s)]

2. Passage 1 is the first in the series, it uses a single use (live:) macro to delay the showing of the 2nd Passage in the series.

Contents of Passage 1

(live: $delay)[{
	(replace: ?output)[(display: "Passage 2")]

3. Each of the other Passages in the series have the same structure as the 1st, that being:
a. Some content to be displayed.
b. A single use (live:) macro to display the next Passage in the series after a delay.

If you press one of the links then that will effect the delay for the Passage being displayed after the current one, as you can't effect the current delay this way.

There is a technique you can use to simulate a variable length delay within a single (live:) macro. You can have the (live:) macro set to a shorter delay that can be factored into each of your possible longer delay options, and then use a counter variable to limit the execution of the contents of the (live:) macro's associated hook.

The following demonstrates this technique by allowing you to control how often a message is updated.

(set: $counter to 0)
(set: $delay to 3)

|output>[counter: $counter]

(live: 1s)[{
	(set: $counter to it + 1)
	(if: $counter % $delay is 0)[
		(replace: ?output)[counter: $counter]

(link-repeat: "A delay of 3")[(set: $delay to 3)]
(link-repeat: "A delay of 6")[(set: $delay to 6)]
(link-repeat: "A delay of 9")[(set: $delay to 9)]

 ... because the remainder operator % needs to do a division to determine it's outcome and because doing a division on a small number takes less time that that of a large number, I would suggest resetting the $counter variable back to zero before it gets too large although I wouldn't reset every-time the remainder is zero because an assignment also takes time to do.

by (170 points)
Thanks heaps, they are great options!

Slowly getting the hang of the syntax:)

Thanks again:)
by (170 points)
reshown by

these options are working perfectly in Harlowe - but I am now actually wanting to use them in Sugarcube.

What are my options for using setting up a named hook and replacing the passage?