0 votes
by (2.2k points)
(set: $var1 to it + 5)(set: $tme to 0)blah blah blah
One. (click: "One.")[(set: $tme to it + 1)(set: $var2 to it - 5)blah blah]
Two. (click: "Two.")[(set: $tme to it + 1)(set: $var3 to it - 5)blah blah]
Three. (click: "Three.")[(set: $tme to it + 1)(set: $var4 to it - 5)blah blah]
(if: $tme is >= 3)[blah blah]

Not only do the variables not decrease, the last line doesn't show up after clicking all the other three even though that's how it should work. It doesn't give me an error at all but it just doesn't work. I've tried restarting everything but even that doesn't work.

Can anyone tell me what's up? Or if it's just a bug or something?

2 Answers

0 votes
by (159k points)
selected by
 
Best answer

At the time a passage is shown to the Reader all it's contents/code is processed to generate the HTML to show to the Reader, the only code that is not processed at that time is code that is within the associated hooks of macros that either required user interaction (like (link:) and (click:) macros) or timer based macros like (live:).

This is why your (if: $tme is >= 3) related code is not working like you expected it to because at the time it was processed $tme equalled zero.

Try something like the following:

<!-- You should initialise a variable before you manipulate it. -->
(set: $var1 to 0)
(set: $var2 to 0)
(set: $var3 to 0)
(set: $var4 to 0)

(set: $var1 to it + 5)\
(set: $tme to 0)\
blah blah blah
(link-reveal: "One.")[{
	(set: $tme to it + 1)
	(set: $var2 to it - 5)
	(print: " blah blah")
	(if: $tme >= 3)[(replace: ?output)[blah blah]]
}]
(link-reveal: "Two.")[{
	(set: $tme to it + 1)
	(set: $var3 to it - 5)
	(print: " blah blah")
	(if: $tme >= 3)[(replace: ?output)[blah blah]]
}]
(link-reveal: "Three.")[{
	(set: $tme to it + 1)
	(set: $var4 to it - 5)
	(print: " blah blah")
	(if: $tme >= 3)[(replace: ?output)[blah blah]]\
}]

[]<output|

notes:
a. You should initialise variables (like the $varX ones) before you manipulate them, ideally this should be done in your story's startup tagged special passage.

b. Don't use the is operator with the mathematical operators when testing for things like greater-than or equal to. Although Harlowe 2 allows this it is like say $tme must be exactly 3 and that $tme can be greater-than or equal to 3 at the same time, and that doesn't make logical sense.

c. I generally suggest using the (link:) related macros instead of (click:) because (click:) needs to search the whole content to find the relevant text/hook, and it keeps doing that anytime the page structure is changed.
eg. whenever the text on the page changes.

d. Try to format your code, it makes it easier to read and understand, both for you and for others.

by (2.2k points)
thank you, I'll be implementing that starup passage
0 votes
by (63.1k points)
How are you testing the variables to know they aren't decreasing? What are the initial values of $var2 through $var4 anyway? We aren't seeing any of that here. The reason the (if:) isn't firing is because it's already been rendered on the page. You'll need to use something dynamic, like a (replace:) or a (live:), to force the already rendered part to be re-rendered. An (if:) itself isn't enough; it's only evaluated once, when the whole page is rendered.
by (2.2k points)
I was using debug mode and I have the variables listed in a footer so I can always see them. I thought the square brackets would make it so that everything in between them would only be done when the macro before it was done. Does it not work like that?

How do I use live? That's what I first tried to use but I couldn't figure out how to use it. Could you give me an example?

I'm sorry, I'm really not good at this, thank you for helping me.
...