0 votes
by (590 points)
closed by
I know of (live:) how it reruns the passage over and over, and it works well for updating text when the input is situated next to the for me in the passage, but is there a way to selectively update text on a page without having to contain it all with (live:)?

 

for example:

|a>[You have $number cows!]

(link: "Buy a cow")[(set:$number to it +1)(update: ?a)]

 

surely you understand what my fictional (update:) macro would do, just force the named hook ?a to rerun and redisplay its contents. i know (live:) works, but my low spec computer absolutely cannot handle how it works, especially below 1s or moderate amount of text. and also if there is a large space of text or other code between the namedhook and the input, using (live:) forces me to contain it all, it doesn't work very well for me.

 

do i just somehow turn the (update:) into a (live:) prefix to be applied to the named hook, and use (stop:) so it effectively only runs once?

 

any help is appreciated, i am entirely without knowledge in programming and only a few days into learning twine. i didn't find any similar question here. also the manual (https://twine2.neocities.org/) doesn't show much usage for named hooks, thanks
closed with the note: (replace:) :)

1 Answer

+2 votes
by (63.1k points)
selected by
 
Best answer

I believe (replace:) does what you want. 

You have |cows>[$cows] cows. 

{
(link-repeat: "Buy Cow")[ 
    (if: $money >= 100)[
        (set: $money to it - 100)
        (set: $cows to it + 1)
    ](else:)[
        (replace: ?error)[\
            not enough money! \
        ] 
    ] 
    (replace: ?money)[$money]
    (replace: ?cows)[$cows]
]
}
|error>[]
Money: |money>[$money]

I didn't test this code, so it may contain syntax errors, but I think you should be able to get the idea from it. 

by (590 points)
yes! i was scouring the manual just now probably as you typed the response and i saw (replace:). your example is exactly the function i'm looking for, replacing a named hook containing a variable via user input/clicking

 

thank you
...