Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Infinite replace macro?

Hi all,

I currently have a macro set up in Harlowe/2.0.2 to cycle through a set of 4 phrases using the following code:

[Thanks]<shout|
(click: ?shout)[(replace: ?shout)[[Thants]<shout2|] ]
(click: ?shout2)[(replace: ?shout2)[[France]<shout3|] ]
(click: ?shout3)[(replace: ?shout3)[[Franks]<shout4|] ]
I'd love this to cycle infinitely so that clicking Franks takes you back to Thanks and repeats the order. Is this possible? I tried the following line to no luck.

(click: ?shout4)[(replace: ?shout4)[[Thanks]<shout|] ]
Any advice appreciated!

Comments

  • NOTE: Even though the following solution works, I DON'T think that it it is a good solution because it results in a never ending (live:) macro.

    A. First an explanation about hooks, the (replace:) macro and why you were having problems with your example:
    The (replace:) macro does not replace a hook, it replaces the contents of a hook, which sounds like the same thing but isn't.
    So in your example once you have clicked all the links the HTML of your story looks something like the following:

    <tw-hook name="shout">
    <tw-hook name="shout2">
    <tw-hook name="shout3">
    <tw-hook name="shout4">Franks</tw-hook>
    </tw-hook>
    </tw-hook>
    </tw-hook>
    As you can see you end up with hooks within hooks, so when you tried to add the extra (click: you would of ended with two hooks with the same name, which is not good.


    B. Now, the possible solution to your problem using 2 variables, and the (link:) and (live:) macros!

    1. First the code:

    (set: $selected to false)
    (set: $shout to "Thanks")

    |prompt>[(link: "$shout")[(set: $selected to true)]]

    {(live: 250ms)[(if: $selected)[(set: $selected to false)(if: $shout is "Thanks")[(set: $shout to "Thants")](elseif: $shout is "Thants")[(set: $shout to "France")](elseif: $shout is "France")[(set: $shout to "Franks")](elseif: $shout is "Franks")[(set: $shout to "Thanks")](replace: ?prompt)[(link: "$shout")[(set: $selected to true)]]]]}
    2. The (live:) macro is checking the current value of the $selected variable every 1/4 of a second and if it changes to true it updates the value of the $shout variable to what should be displayed next. It then updates the ?prompt so the link works again.

    A copy of the above (live:) macro formated so it is more readable:

    {
    (live: 250ms)[
    (if: $selected)[
    (set: $selected to false)
    (if: $shout is "Thanks")[
    (set: $shout to "Thants")
    ]
    (elseif: $shout is "Thants")[
    (set: $shout to "France")
    ]
    (elseif: $shout is "France")[
    (set: $shout to "Franks")
    ]
    (elseif: $shout is "Franks")[
    (set: $shout to "Thanks")
    ]
    (replace: ?prompt)[
    (link: "$shout")[
    (set: $selected to true)
    ]
    ]
    ]
    ]
    }
    3. The problem with the above (live:) macro.
    Live macros don't stop looping unless you manually tell them to by using the (stop:) macro, the problem in the above is that because you want the link to keep changing every time it is clicked there is no simple way to know when to manually stop the (live:) macro.
  • It seems best not to use the live macro, so maybe I'll just find another way around this - but thanks all the same for the thorough answer!
Sign In or Register to comment.