Hello, I’m writing a gamebook involving a time loop, so you end up getting sent back to certain sections multiple times, but having new knowledge and items each time. I can’t do this linearly, recreating the section each “loop” because depending on choices made, readers could have any number of combinations of new knowledge and items. So what I’d like to do is use “set” commands and “if” commands to reveal new text and links, depending on what you have.
I figured this would be as simple as doing something like…
(if:$DrownedTemple)[You see the drowned temple in the distance.]
in the loop section, and (set: $drownedtemple to true)
in the section where you learn about the drowned temple
… however, it isn’t working. I’m getting errors not only in the boolean (The (if:) macro’s 1st value is the number 0, but should be a boolean), but also I think because if: statements only check the FIRST time the section is created, it wouldn’t do what I want.
But I am probably misunderstanding all of this. Coding is not my forte. Any help is appreciated!
You’re setting the variable $DrownedTemple to true, but you’re checking the value of $drownedtemple. Those are different variables, because capitalization matters in variable names. Your capitalization should always be consistent.
Thank you for pointing that out. Still, whenever I run it, I get
The (if:) macro’s 1st value is the number 0, but should be a boolean.
EDIT: Nevermind, I have to apparently type in (if:$DrownedTemple is true) Missing the “true” is what creates the error. You can’t just leave it blank. Maybe that’s just a 3.3.1 thing, since the documentation for Harlowe (now 3.3.5) shows leaving it blank.
Thank you for your assistance! I’m glad it was just a little thing in both cases.
I don’t use Harlowe much, so take this with a grain of salt, but what seems to be happening is the (if:) macro throws that error when $DrownedTemple is undefined. Adding an is true fixes that, but it’s generally good practice to initialize your variables when your game starts. You can do it by adding (set: $DrownedTemple to false) to a passage tagged startup.
As mentioned by svlin, a variable Name is letter case sensitive, so $DrownedTemple and $drownedtemple would be considered two different variables.
If you reference (try to use) a variable that hasn’t been initialised (assigned a value) yet then Harlowe will automatically assign a default Numerical value of 0 (zero) to that variable before using it.
Values can have different data-types, the 0 (zero) mentioned previously is a Number, and the true value you later assigned to the variable in your example is a Boolean.
The (if:) macro requires the conditional expression passed to it to evaluate to a Boolean true or false.
So when Harlowe went to evaluated your (if: $DrownedTemple) expression the uninitialized $DrownedTemple variable was set to 0 zero, which changed your expression to be (if: 0). And because Number 0 (zero) is not a Boolean value Harlowe showed you the error it did.
As explained by svlin, all you needed to do was initialise that variable to false within your project’s startup tagged Passage. And then you could of left your code as (if: $DrownedTemple), which is the correct syntax for checking if a Boolean variable current equals true.