Learn

Chapter 04 Variables & Data Types

#031 Boolean Variables

Is the door locked? Does the player have the key? Yes or no. That's what Booleans store.

  • 1:14 video
  • Written lesson
  • Beginner
Video lesson: Boolean Variables, 1:14

True or false

Most gameplay questions have only two answers. Is the enemy dead? Is the light on?

A Boolean variable stores exactly one of two values: true or false. Its Default Value is a checkbox, and unchecked means false.

Name it like a question, Is Dead or Has Key, so every Branch reads clearly. Many nodes return a Boolean: comparisons like greater than, Is Valid, or Contains Item.

NOT flips the value. Set Flashlight On to NOT Flashlight On, and every key press toggles the light.

Example: a locked door

The door opens only when the player Has Key and Is Near Door. AND returns true only when both inputs are true.

Near the door, but no key: false, and the door stays shut. Key picked up: both are true, Branch takes True, and the door opens.

Need just one of them? Use OR: it’s true when at least one input is true.

The trap

AND doesn’t skip its second input: both inputs are read, even when the first one is false. So Is Valid AND Health greater than zero still reads Health from an empty reference, and you get an Accessed None error.

Check Is Valid with its own Branch first, then read Health.

In short

Two values, one question: true or false.

Covered in this lesson

  • Boolean
  • NOT
  • AND
  • OR
  • Branch
  • Is Valid
  • Contains Item

Newsletter

Development updates are coming to your inbox.

The newsletter opens soon. Until then, new lessons, tools and Beach Hunters progress appear first on our channels, linked below.