Menu
CoddyTech

Boolean

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 7 of 92.

A Boolean has only two possible values: true or false. Its type in GDScript is bool.

The values are written in lowercase and without quotes:

var is_alive = true
var has_key = false

This creates two variables: is_alive holds true and has_key holds false. print(is_alive) shows true.

Capitalization matters. True and TRUE are not Booleans in GDScript: they are read as names, no variable has those names, and Godot reports an error before the program runs.

With quotes, "true" is a String that contains the word true. It prints the same, but it is text, not a Boolean.

Booleans store yes-or-no facts, such as whether a door is open or the game is over. The chapters on operators and decisions use them to make choices.

challenge icon

Challenge

Beginner

Create two Boolean variables under the comment:

  • is_alive with the value true
  • has_key with the value false

Do not change the print() lines. The program prints:

is_alive = true
has_key = false

Try it yourself

extends Node

func _ready():
	# Create the variables is_alive and has_key below
	
	# Don't change the lines below
	print("is_alive = ", is_alive)
	print("has_key = ", has_key)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online GDScript compiler