0 votes
by (130 points)

Hello! I'm trying to make it so this one link only appears if two other passages have been visited. Here's the code, followed by a quick bit of context:

(if: $FVtournament and $FVbody)[[[I think I'm gonna go, for now.|Leave room FV]]]

Essentially, the player talks to a character - they have three potential questions to ask him. I want the "Leave room" prompt to only appear after they've asked all three questions, so I'm trying to make it so the code only displays the option to leave once the two other questions have been asked. For example, question 1 is about his body - "$FVbody" is set to true in the passage where you ask him about it.

So how exactly can I format the code to make it work? The current error message is: "I can only use 'and' to join booleans, not the number 0.►If one of these values is a number, you may want to write a check that it 'is not 0'. Also, if one is a string, you may want to write a check that it 'is not "" '."

I'm not super knowledgeable on code, so I apologize if I'm missing a very obvious answer. While I'm at it, my story has been created in Harlowe 1 and I've kept it that way thus far, but I notice a lot of people use Sugarcube instead. What I'm working on is pretty large-scale, and will likely take another year or two to fully complete - I'm 20 000 words or so into it, is it worth changing over to Sugarcube at this point? If it gives way more freedom, I might want to switch over, despite the few bits of code I'd have to modify. 

Let me know your thoughts, and thank you very much!

1 Answer

+1 vote
by (63.1k points)
edited by

You need to initialize these variables in your startup-tagged passage, otherwise, their values default to 0, not false. I assume you're only setting them to true, and only when they're encountered. If so, that's the problem.

You might be able to compare them directly with boolean true, but it's still best to initialize them. Also, make sure you're not quoting your booleans, true is not the same as "true".

::init [startup]
(set: $FVbody to false)
(set: $FVtournament to false)

::some passage
(set: $FVbody to true)

::another passage
(if: $FVtournament and $FVbody)[...]

More info on the startup tag: 

https://twine2.neocities.org/#passagetag_startup

Note: 0, empty strings, null, and undefined, among a few other values, evaluate to false in normal JavaScript in boolean contexts, like if statements. This is not the case in Harlowe, where type is enforced. 

by (130 points)
Thanks a lot, it worked perfectly! I had read about startup a long while ago, but I had completely forgotten it existed. Gonna be of great use, now!
by (63.1k points)
Also, as far as moving to sugarcube, I wouldn't if you're already that far in. If you find yourself needing features that harlowe doesn't provide, then you might be in trouble, since harlowe is difficult to extend. That said, cutting features isn't universally a bad thing, sometimes it helps to focus and to save those big ideas for later. If you've come this far, you might as well stick it out.

I don't want to discourage you from checking out sugarcube and giving it a try though, because it is a great format. But so is harlowe. They just have different goals and were made by different people to do different things.
...