Interactive storytelling is fun and creative. You make choices. The story changes based on those choices. Tools like Twine make this easy. One of the most popular Twine story formats is Harlowe.
In Harlowe, you use variables to track choices. Boolean values are often used. These values are either true or false. In many stories, you need to switch a boolean. You want to go from true to false, or false to true.
This article will show you how to invert a boolean value in Harlowe. You’ll also learn how this trick helps make your story smarter and more fun.
What Is a Boolean Value?
A boolean is a simple yes or no. In coding terms, it’s either:
-
true
-
false
You use booleans to track many things in Twine stories:
-
Did the player find the key? (
$hasKey
) -
Is the light on? (
$lightOn
) -
Has the door been opened? (
$doorOpen
)
Booleans make your story interactive. You can change paths based on them. You can lock or unlock options. You can change what happens in each scene.
Why Invert Boolean Values?
Sometimes, you want to flip the state of a variable. Maybe the door is closed. The player opens it. You change $doorOpen
from false
to true
.
Now what if the player closes the door again? You need to invert the value.
So if:
$doorOpen is true
Then you do:
(set: $doorOpen to not $doorOpen)
Now, $doorOpen
becomes false
.
You can do this again and again. It flips back and forth. It’s easy and powerful.
Basic Syntax in Harlowe
To invert a boolean in Harlowe, use the not
keyword.
Here’s the basic rule:
(set: $variable to not $variable)
Let’s say you have this:
(set: $lightOn to true)
To invert it:
(set: $lightOn to not $lightOn)
Now it becomes false
.
If you do it again, it becomes true
again.
This works every time.
Real Story Example: Light Switch
Let’s create a short example.
(set: $lightOn to false)
You enter a dark room. The switch is on the wall.
[[Flip the switch|RoomAfterSwitch]]
In the next passage, use this:
(set: $lightOn to not $lightOn)
(if: $lightOn)[
The light turns on. You can now see the whole room.
]
(else:)[
The room goes dark again.
]
[[Go back|Room]]
Every time you click “Flip the switch”, the light changes. It turns on and off. This is boolean inversion in action.
Tip 1: Use Clear Variable Names
Always choose names that make sense. This helps you avoid confusion.
✅ Use: $doorOpen
, $hasKey
, $lightOn
❌ Avoid: $d
, $x1
, $var123
Good names help you read and change your code later. You can also spot bugs faster.
Tip 2: Keep Track of Boolean States
In bigger stories, you may have many booleans. It helps to track them in one place.
Use a debug passage or a testing passage. Print all your booleans for quick checks.
Example:
Boolean States:
* Light: $lightOn
* Door: $doorOpen
* Key: $hasKey
Use this only during testing. Remove it before publishing.
Tip 3: Invert Only When Needed
Don’t invert a boolean unless it makes sense in the story. Inversion should reflect a real change.
Right:
-
Flip a light
-
Open/close a door
-
Toggle music
Wrong:
-
Change a value just for fun
-
Invert without a player action
Every change should come from choice or action.
Tip 4: Combine Booleans with Conditions
You can use boolean values inside if
and else
statements. This controls what the reader sees.
Example:
(if: $hasKey)[
You unlock the chest.
]
(else:)[
The chest is locked. You need a key.
]
You can also invert inside conditions:
(if: not $hasKey)[
You cannot open the chest.
]
This gives you more power. You can write flexible paths.
Tip 5: Use Booleans to Lock and Unlock Content
Do you want to show hidden content after a choice? Use a boolean.
For example, after reading a book:
(set: $readBook to true)
Later, you can show a secret message:
(if: $readBook)[
You remember the line from the book: "Trust no one."
]
If the reader didn’t read the book, they won’t see it. This makes the story feel alive.
Advanced Use: Inverting with Buttons
You can use a link or button to invert a boolean. This adds a game-like feel.
Example:
(set: $lampOn to false)
(turn on lamp)[
(set: $lampOn to not $lampOn)
]
You can go further with more logic:
(if: $lampOn)[
The room is bright.
]
(else:)[
The room is dark.
]
You now have a working toggle button.
Common Mistakes to Avoid
Even simple tasks can go wrong. Let’s see some common errors when using not
in Harlowe.
1. Spelling Errors
Make sure you write not
correctly. Harlowe is case-sensitive.
Wrong:
(set: $lightOn to NOT $lightOn)
Correct:
(set: $lightOn to not $lightOn)
2. Using not
on non-boolean
Only use not
on boolean values. It won’t work well with numbers or strings.
Wrong:
(set: $score to not $score)
3. Forgetting to Set Initial Value
You must set the variable before inverting.
Wrong:
(set: $doorOpen to not $doorOpen)
If $doorOpen
has no value yet, this causes errors.
Right:
(set: $doorOpen to false)
(set: $doorOpen to not $doorOpen)
Always initialize first.
Combining Boolean Inversion With Story Events
Here are ways to use boolean inversion in different story types.
Mystery Game
Track if the player has checked a clue.
(set: $checkedCloset to not $checkedCloset)
If they check again, give different text.
Horror Game
Switch lights off and on for creepy effects.
(set: $power to not $power)
Then add sound or visuals for extra mood.
Puzzle Game
Track puzzle pieces found.
(set: $hasPiece1 to not $hasPiece1)
You can then show puzzles when all are true.
Building a Mini Game with Inverted Booleans
Let’s try a mini game: a magic lamp.
(set: $lampLit to false)
You find a strange lamp on the ground.
[[Rub the lamp|MagicLamp]]
Next passage:
(set: $lampLit to not $lampLit)
(if: $lampLit)[
A genie appears! He offers you three wishes.
]
(else:)[
The lamp goes cold. The genie disappears.
]
[[Rub it again|MagicLamp]]
Each time, the state flips. The story responds. This adds surprise and fun.
Benefits of Boolean Inversion in Interactive Stories
-
Adds realism
-
Reacts to player actions
-
Creates surprise
-
Saves code lines
-
Keeps story logic clean
As a result, your story becomes smart and alive.
Cheat Sheet: Invert Boolean in Harlowe
Task | Code Example |
---|---|
Set to true | (set: $doorOpen to true) |
Set to false | (set: $doorOpen to false) |
Invert value | (set: $doorOpen to not $doorOpen) |
Show if true | (if: $doorOpen)[The door is open.] |
Show if false | (if: not $doorOpen)[The door is closed.] |
Toggle with link | `[[Toggle |
Final Thoughts
Boolean values are simple, but powerful. With one line, you can change the direction of your story. By learning how to invert boolean values in Harlowe, you unlock a new level of control.
Always plan your variables. Keep them meaningful. Use inversion when it adds value to the story. Add conditions, toggles, and effects to create rich experiences.
Twine is a tool for storytellers. Harlowe helps bring your ideas to life. And with boolean logic, your readers feel the impact of every choice.
Now, go build something amazing. Let your story respond, twist, and grow. Start with a boolean. Then, flip the world.