Can someone help with my thing its twine

Twine Version: Harlowe 3.3.8

I need it so that when I press an image, it changes and adds +1 to the variable $health (its not actually health I just named it that)

My code is that when you press an image, it changes images and then adds +1. I need it so that when there is enough points it will display text.

(set: $health to 0) 
(link-replace: "<img src='' width='100px' height='100px'>")[<img src='' width='100px' height='100px'>(set:$health to($health +1))]
(if: $health is 1)[huh]
(else:) [do it]

When I’m in test mode, on the panel it says that it was +1 but the text doesn’t change. It just says “do it” and wont change even though $health is 1 ??? I need it to change to “huh” instead of “do it”.

The code you have is running, but not automatically updating.

The example in the Harlowe manual for the (rerun:) macro should help you solve your problem.

Edit: Or (replace:) might be better.

1 Like

By default the content of the Passage being visited is only processed during the Passage Transition phase. Which means any conditional logic in that content, like your (if:) + (else:) macro usage, is only evaluate during that processing.

And this is why the conditional text being displayed didn’t automatically update when the value of referenced variable was dynamically changed via the selection of the link.

You need to manually cause / trigger such an update yourself, and one of the easier ways to do that is by wrapping the area you want to update in a Named Hook and then use macros like (rerun:) or (replace:) on that hook.

	(link-replace: "<img src='' width='100px' height='100px'>")[
		<img src='' width='100px' height='100px'>
		(set: $health to it + 1)
		(rerun: ?message)
|message>[(if: $health is 1)[huh](else:)[do it]]

wow thanks guys it worked