GDScript Full Notes
GDScript Full Notes
GDScript
Complete Beginner to Intermediate Notes
For Godot 4 | Explained Like You Are 10 Years Old
For future African game developers
GDScript is the language you use to give your game a brain. Without GDScript your game is just
pictures sitting on a screen doing nothing. GDScript is what makes your character walk, your
enemy chase you, your story progress, your music play, and your choices matter.
Think of your game like a puppet show. The puppets (characters, backgrounds, buttons) are your
Nodes and Scenes. GDScript is the puppeteer — the invisible hands that make everything move
and react.
GDScript was invented just for Godot. That means it was designed to make game development
easier, not harder. It looks more like plain English than almost any other coding language.
NOTE: GDScript is the right choice for where you are right now. Do not let anyone convince you
otherwise.
A variable is a box with a label on it. You put information inside the box. Whenever you need that
information later you just call the box by its label name.
This is the most important concept in all of programming. Everything else builds on variables. Take
your time to understand this deeply.
NOTE: The # symbol starts a comment. Comments are notes you write for yourself. Godot
ignores them completely. Always write comments to explain your code to your future self.
REMEMBER: If you try to change a constant later in your code, Godot will give you an error.
That is the whole point — constants protect important values from being accidentally changed.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
Not all information is the same. A name is different from a number. A true/false answer is different
from a list of items. GDScript has different types to handle each kind of information. These are
called Data Types.
Strings — Text
A String is any text. It must be wrapped in double quotes. You can put words, sentences, numbers
that look like text, symbols — anything inside the quotes.
var character_name = "Kwame"
var dialogue = "The ancient spirit has awakened."
var empty_string = ""
NOTE: In Godot, x goes from left to right. y goes from top to bottom. So y=0 is the TOP of the
screen. This confuses beginners at first but you will get used to it.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
Operators are the symbols you use to do calculations and compare values. You already know most
of them from school maths.
Maths Operators
Code What it means
a + b Add. Example: 10 + 5 = 15
a - b Subtract. Example: 10 - 3 = 7
a * b Multiply. Example: 4 * 3 = 12
a / b Divide. Example: 10 / 2 = 5
a % b Remainder after dividing. Example: 10 % 3
=1
a += b Add and save. Same as: a = a + b
a -= b Subtract and save. Same as: a = a - b
a *= b Multiply and save. Same as: a = a * b
a /= b Divide and save. Same as: a = a / b
var score = 0
score += 10 # score is now 10
score += 10 # score is now 20
score -= 5 # score is now 15
score *= 2 # score is now 30
If statements are how your game makes decisions. Every single choice in your game — what
happens when the player dies, what the character says, which path opens — is controlled by if
statements.
An if statement says: IF this condition is true, do this thing. Otherwise, do something else.
Basic If Statement
if player_health <= 0:
print("Game over!")
Read this like English: IF the player's health is 0 or below, print Game over. The four spaces (called
indentation) before print are NOT optional. In GDScript, indentation is how Godot knows which
code belongs inside the if statement.
REMEMBER: Indentation is everything in GDScript. If your code is not indented correctly,
Godot will give you an error. Always use Tab or 4 spaces — be consistent.
If / Else
Else means: if the if condition was NOT true, do this instead.
if player_health <= 0:
print("Game over!")
else:
print("Keep fighting!")
Godot checks each condition from top to bottom and stops at the first one that is true. Only one
block runs.
if player_choice == 1:
print("The elder nods slowly and begins to speak...")
elif player_choice == 2:
print("You raise your weapon. The elder steps back.")
elif player_choice == 3:
print("You flee into the forest, heart pounding.")
else:
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
A loop makes your code repeat. Instead of writing the same instruction 100 times, you write it once
and tell Godot how many times to repeat it. Loops save you enormous amounts of time.
range(5) generates the numbers 0, 1, 2, 3, 4. The variable i holds the current number each time the
loop runs. The loop runs 5 times total.
# range with a start and end:
for i in range(1, 6):
print(i) # prints 1, 2, 3, 4, 5
print("Launch!")
REMEMBER: Be careful with while loops. If the condition never becomes false, your loop runs
forever and crashes your game. Always make sure something inside the loop will eventually
make the condition false.
A function is a named block of instructions. You write the instructions once, give the block a name,
and then you can run all those instructions just by calling the name. This is one of the most
powerful tools in programming.
Think of a function like a recipe. You write the bread recipe once. Whenever you want bread, you
just say bake_bread() instead of repeating all 20 steps every single time.
Creating a Function
func show_welcome():
print("Welcome to The Last Kingdom")
print("Your journey begins now")
func is the keyword. show_welcome is the name you chose. The colon and indented lines below
are the instructions that run when this function is called.
Calling a Function
# Somewhere else in your code, just write the name:
show_welcome()
func _ready():
print("Scene loaded! Setting up...")
player_health = 100
func _process(delta):
# This runs 60 times per second
if Input.is_action_pressed("ui_right"):
position.x += 200 * delta
NOTE: The delta parameter in _process(delta) is the time since the last frame in seconds.
Multiplying your speed by delta makes movement smooth regardless of whether the game runs
at 30fps or 60fps.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
An Array is a list. Instead of creating 10 separate variables for 10 enemies, you create one Array
that holds all 10. Arrays are incredibly useful for managing groups of things in your game.
Creating an Array
var inventory = [] # empty array
var weapons = ["sword", "bow", "shield"]
var enemy_health = [100, 80, 60, 40]
var story_flags = [false, false, false] # three story events, all unseen
REMEMBER: The index starts at 0. The first item is always [0]. If your array has 3 items, the
last index is [2]. Trying to access [3] on a 3-item array will crash your game.
[Link]("ancient_scroll")
print([Link]()) # 4
print([Link]("key")) # true
A Dictionary stores information in pairs — a label (called a key) and its value. Instead of
remembering that index 0 is the name and index 2 is the health, you just use the label. Much easier
to read and understand.
Creating a Dictionary
var player = {
"name": "Amara",
"health": 100,
"level": 1,
"has_sword": false
}
# Changing a value:
player["health"] = 80
player["has_sword"] = true
var character_stats = {
"name": "Kwame",
"strength": 8,
"speed": 5,
"wisdom": 10
}
In Godot every script is attached to a Node, and every Node is a kind of object with its own data
and abilities. Understanding this is what makes you go from a beginner to someone who can build
real games.
When you extend a Node type, your script automatically gets all the abilities of that Node type for
free. A CharacterBody2D already knows about physics and collision. You do not have to build those
yourself.
NOTE: When you add @export before a variable, you can select your Node in the scene and
see those variables in the Inspector on the right side. Change them there and the change
applies immediately in the game.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
Signals are messages that Nodes send to tell other Nodes that something happened. Think of it like
a telephone call — one Node calls another to say: hey, this thing just happened, do something
about it.
For example: when a button is pressed, it sends a pressed signal. Your script can listen for that
signal and do something when it receives it.
func _ready():
# Connect this button's pressed signal to our function
[Link](on_button_pressed)
func on_button_pressed():
print("Button was clicked!")
# This is where you change the story, open a scene, etc.
func finish_chapter(num):
print("Chapter " + str(num) + " complete!")
# Send the signal to anyone listening
chapter_completed.emit(num)
NOTE: Signals keep different parts of your game separate and clean. Instead of every part of
your game knowing about every other part, Nodes just shout signals and whoever is listening
responds. This is called loose coupling and it is excellent game design practice.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
Godot gives you hundreds of ready-made functions you can use immediately. Here are the most
important ones you will use constantly when building your game.
var whole = 5
var decimal = float(whole) # converts int to float: 5.0
Now let us put everything together with real examples from the kind of story game you want to
make. These are not made up examples — you can use these directly in your first game.
var dialogue_lines = [
"The village elder looks at you with tired eyes.",
"\"You are the chosen one,\" he says slowly.",
"\"The Kingdom of Kongo needs you.\"",
"\"Will you accept this burden?\""
]
var current_line = 0
func _ready():
show_current_line()
func show_current_line():
if current_line < dialogue_lines.size():
$[Link] = dialogue_lines[current_line]
else:
print("Dialogue finished")
show_choices()
func advance_dialogue():
current_line += 1
show_current_line()
func _input(event):
if event.is_action_pressed("ui_accept"):
advance_dialogue()
func _ready():
update_health_bar()
func take_damage(amount):
current_health -= amount
current_health = clamp(current_health, 0, max_health)
update_health_bar()
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
if current_health == 0:
die()
func heal(amount):
current_health += amount
current_health = clamp(current_health, 0, max_health)
update_health_bar()
func update_health_bar():
$[Link] = current_health
func die():
print("Character has died")
get_tree().change_scene_to_file("res://scenes/game_over.tscn")
var save_data = {
"chapter": 1,
"player_name": "Amara",
"choices_made": [],
"items_collected": []
}
func save_game():
var file = [Link]("user://[Link]", [Link])
file.store_var(save_data)
[Link]()
print("Game saved!")
func load_game():
if FileAccess.file_exists("user://[Link]"):
var file = [Link]("user://[Link]", [Link])
save_data = file.get_var()
[Link]()
print("Game loaded! Chapter: " + str(save_data["chapter"]))
else:
print("No save file found. Starting new game.")
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
Print this page and stick it above your desk. These are the most important GDScript patterns you
will use every single day.
Variables
var name = "value" # String variable
var number = 100 # int variable
var decimal = 3.14 # float variable
var flag = true # bool variable
const MAX = 100 # constant (never changes)
@export var speed = 200 # shows in Inspector
If Statements
if condition:
# do this
elif other_condition:
# do this instead
else:
# do this if nothing above was true
Loops
for i in range(5): # repeat 5 times
print(i)
Functions
func function_name(): # basic function
print("hello")
func with_return():
return 42 # returns a value
Arrays
var list = [1, 2, 3]
[Link](4) # add item
list.remove_at(0) # remove first item
print([Link]()) # how many items
print(list[0]) # access first item
Dictionaries
var data = {"key": "value"}
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey
You now have more GDScript knowledge than most people who say they want to make games.
The difference between dreamers and developers is simple: developers open the editor and start
typing even when they do not feel ready.
You will make mistakes. Your code will break. Godot will show you red errors. That is not failure —
that is learning. Every single error message tells you exactly where the problem is and gives you
something to search for on YouTube or in the Godot documentation.
The African stories you carry with you — the mythology, the history, the moral frameworks passed
down through generations — are more valuable than any game engine or programming language.
The technical skills you are building right now are just the tools to share those stories with the
world.
The world has never played a deeply African story-driven game built with real cultural knowledge
and love. That gap in the market has your name on it. Fill it.
Your next step: Open Godot, create a new script, and type your first variable.