Number Value Variable not changing

Twine Version: 2.4.0

I’m attempting to make a game on Twine, but I’ve run into an issue. I’m sure I’m making a basic mistake here, but I can’t quite figure it out. I need to create a gate for the player to continue once they choose their backgrounds. They can only choose two, so I need to create an If and Only if statement for 2 backgrounds. If that’s true, then the continue button will appear.

I realized that first I need to get a value for number of backgrounds, so I wrote the following code. The backgrounds use a checkbox macro:

(checkbox: 2bind $bkthtr,"Theatre")

and according to the test screen, the Boolean functions are working. Checking off the checkbox turns $bkthtr from false to true. So then I wrote the following code to try to determine the number of backgrounds checked off.

(set: $bkcheck to 0)

(if:$bkcher is true)[(set: $bkcheck to it + 1)]
(if:$bkthtr is true)[(set: $bkcheck to it + 1)]
(if:$bksprt is true)[(set: $bkcheck to it + 1)]
(if:$bkmath is true)[(set: $bkcheck to it + 1)]

The issue is, $bkcheck shows up in the test as always equalling 0. If I had to guess, I’m misunderstanding some sort of fundamental aspect of how the timing works here. What I want to tell the system is “when this box is clicked, add 1 and only 1 to $bkcheck,” but I think something in the timing is off here. If anyone could help explain why this code isn’t working that would be greatly appreciated.

Here’s what I mean by the “test screen.” Shows two boxes clicked, notice the true Boolean variable.

Please let me know what I’m doing wrong and if you need any other information.

1 Like

Are your (checkbox:)s and (if:)s in the same passage? If so, then that’s your problem. In general, passages are processed once during rendering, so the (if:)s are processed before the player can interact with the (checkbox:)s.

If the above is the case, you’ll either need move the (if:)s to a subsequent passage or use a macro to delay the logic until after the player has interacted with the (checkbox:)s.

Is there a way to loop the if statement every 2 seconds or so? I’m having trouble finding a “repeat” macro or something similar.