0% found this document useful (0 votes)
10 views26 pages

GDScript Full Notes

The document provides comprehensive notes on GDScript for Godot 4, aimed at beginner to intermediate African game developers. It covers essential programming concepts such as variables, data types, operators, control structures, and loops, along with practical examples to illustrate their use in game development. Each chapter is designed to simplify complex ideas, making them accessible for young learners and new developers.

Uploaded by

ngangapetersammy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views26 pages

GDScript Full Notes

The document provides comprehensive notes on GDScript for Godot 4, aimed at beginner to intermediate African game developers. It covers essential programming concepts such as variables, data types, operators, control structures, and loops, along with practical examples to illustrate their use in game development. Each chapter is designed to simplify complex ideas, making them accessible for young learners and new developers.

Uploaded by

ngangapetersammy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

GDScript
Complete Beginner to Intermediate Notes
For Godot 4 | Explained Like You Are 10 Years Old
For future African game developers

WHAT IS INSIDE THESE NOTES


• Chapter 1 — What is GDScript and why it matters
• Chapter 2 — Variables: Boxes that hold information
• Chapter 3 — Data Types: Different kinds of information
• Chapter 4 — Operators: Doing maths and comparisons
• Chapter 5 — If Statements: Making decisions
• Chapter 6 — Loops: Repeating things automatically
• Chapter 7 — Functions: Writing instructions once, using them forever
• Chapter 8 — Arrays: Lists of things
• Chapter 9 — Dictionaries: Labelled information
• Chapter 10 — Classes and Nodes: Building real game objects
• Chapter 11 — Signals: How parts of your game talk to each other
• Chapter 12 — Built-in Functions: Tools Godot gives you for free
• Chapter 13 — Real Game Examples: Putting it all together
• Chapter 14 — Quick Reference Sheet: Everything on one page
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 1: WHAT IS GDSCRIPT?

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.

Why GDScript and Not Python, Java, or C++?


You may have heard of other coding languages. Here is the honest truth about them for your
situation:

Code What it means


GDScript Made for Godot. Simple, fast to learn,
perfect for your goals.
Python Similar but not built into Godot. Slower for
games.
C++ Very powerful but extremely hard. Used at
big studios after years of experience.
C# Works in Godot but more complex. Learn
later, not now.
JavaScript For websites mainly. Not ideal for what you
are building.

NOTE: GDScript is the right choice for where you are right now. Do not let anyone convince you
otherwise.

How Does GDScript Work?


Every Node in your game can have one GDScript file attached to it. That script is the brain of that
Node. It tells the Node what to do, when to do it, and how to react to things that happen.
When you run your game, Godot reads every script from top to bottom and follows the instructions.
It is like reading a recipe — the computer reads your instructions in order and follows each step.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 2: VARIABLES — BOXES THAT HOLD


INFORMATION

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.

How to Create a Variable


In GDScript you always start with the word var, then give it a name, then an equals sign, then the
value you want to store.
var player_name = "Amara"
var player_health = 100
var player_speed = 200.5
var has_sword = false
var level_number = 1

The Rules for Naming Variables


Godot does not care what you name your variables, but you have to follow these rules or it will give
you an error:
• Names must start with a letter or underscore. Not a number.
• Names cannot have spaces. Use underscore _ between words.
• Names are case sensitive. player_health and Player_Health are different variables.
• Names cannot be Godot keywords like var, if, for, func, etc.

Code What it means


var player_name CORRECT — starts with letter, uses
underscore
var 1player WRONG — cannot start with a number
var player name WRONG — cannot have spaces
var for WRONG — 'for' is a reserved Godot
keyword
var _score CORRECT — underscore at start is
allowed
var PlayerScore CORRECT — capital letters are allowed

Changing a Variable's Value


A variable can change. That is the whole point. Player health goes down when they get hurt. Score
goes up when they collect something. You change a variable simply by writing its name and
assigning a new value.
var player_health = 100

# Later in the game the player gets hurt:


player_health = 80
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

# They get hurt again:


player_health = player_health - 10

# A simpler way to write the same thing:


player_health -= 10

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.

Constants — Boxes That Never Change


Sometimes you want a value that should never change. Like the game's screen width, or the
maximum health a player can ever have. For those you use const instead of var.
const MAX_HEALTH = 100
const GAME_TITLE = "The Last Kingdom of Kongo"
const SCREEN_WIDTH = 1920

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

CHAPTER 3: DATA TYPES — DIFFERENT KINDS OF


INFORMATION

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.

The Main Data Types You Will Use


Code What it means
String Words and text. Always wrapped in
quotes. Example: "Amara", "Game Over"
int Whole numbers with no decimal. Example:
100, 0, -5, 999
float Numbers with a decimal point. Example:
3.14, 100.5, -0.5
bool Only two possible values: true or false.
Used for yes/no decisions.
Array A list of multiple items. Covered fully in
Chapter 8.
Dictionary Labelled information. Covered fully in
Chapter 9.
Vector2 An x and y position. Used to place things
on screen.
Color A colour value. Used to colour things in
your game.

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 = ""

# Joining two strings together (called concatenation):


var full_message = "Hello, " + character_name
# full_message is now: Hello, Kwame

int and float — Numbers


Use int for counting things (lives, score, level number). Use float when you need precision (speed,
position, percentages).
var lives = 3 # int — no decimal
var score = 0 # int — no decimal
var speed = 150.0 # float — has decimal
var volume = 0.75 # float — 75% volume
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

bool — True or False


Bool is one of the most powerful types. So many decisions in your game come down to a simple
yes or no. Is the player alive? Has the door been opened? Is the game paused?
var is_alive = true
var door_is_open = false
var game_paused = false
var player_has_key = false

# Later when player picks up key:


player_has_key = true

Vector2 — Position on Screen


Everything in your 2D game has a position on screen. That position is described with two numbers:
x (how far right) and y (how far down). Vector2 holds both together.
var player_position = Vector2(100, 200)
# Player is 100 pixels from the left, 200 pixels from the top

var center_of_screen = Vector2(640, 360)

# You can access x and y separately:


print(player_position.x) # prints 100
print(player_position.y) # prints 200

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

CHAPTER 4: OPERATORS — DOING MATHS AND


COMPARISONS

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

Comparison Operators — Asking Questions


These operators ask a question and give you a true or false answer. They are used constantly
inside if statements.

Code What it means


a == b Is a EQUAL to b? Example: 5 == 5 is true.
5 == 3 is false.
a != b Is a NOT EQUAL to b? Example: 5 != 3 is
true.
a > b Is a GREATER than b? Example: 10 > 5 is
true.
a < b Is a LESS than b? Example: 3 < 10 is true.
a >= b Is a GREATER THAN OR EQUAL to b?
Example: 5 >= 5 is true.
a <= b Is a LESS THAN OR EQUAL to b?
Example: 4 <= 5 is true.
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

Logical Operators — Combining Questions


Code What it means
and Both must be true. Example: health > 0
and has_weapon
or At least one must be true. Example:
has_key or door_is_unlocked
not Flips true to false and false to true.
Example: not game_paused
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 5: IF STATEMENTS — MAKING DECISIONS

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!")

If / Elif / Else — Multiple Choices


Elif means: else if. Use it when you have more than two possibilities.
if player_health <= 0:
print("Dead")
elif player_health <= 25:
print("Critical — almost dead!")
elif player_health <= 50:
print("Injured — be careful")
else:
print("Healthy")

Godot checks each condition from top to bottom and stops at the first one that is true. Only one
block runs.

Real Game Example — Story Choices


This is exactly how you would handle player choices in your visual novel game. The player picks an
option, and GDScript decides what happens next.
var player_choice = 1 # 1 = talk, 2 = fight, 3 = run

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

print("You stand frozen, unable to decide.")


GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 6: LOOPS — REPEATING THINGS


AUTOMATICALLY

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.

The For Loop — Repeat a Set Number of Times


# Print numbers 0 to 4
for i in range(5):
print(i)

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

# Looping through a list of names:


var warriors = ["Amara", "Kwame", "Zola"]
for warrior in warriors:
print(warrior + " is ready for battle")

The While Loop — Repeat Until a Condition Changes


A while loop keeps repeating for as long as a condition is true. As soon as the condition becomes
false, it stops.
var countdown = 5

while countdown > 0:


print(countdown)
countdown -= 1

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.

Break and Continue


# break — exit the loop immediately
for i in range(10):
if i == 5:
break # stop when i reaches 5
print(i) # prints 0, 1, 2, 3, 4

# continue — skip this round and go to the next


for i in range(5):
if i == 2:
continue # skip number 2
print(i) # prints 0, 1, 3, 4
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 7: FUNCTIONS — WRITE ONCE, USE FOREVER

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()

# You can call it as many times as you want:


show_welcome()
show_welcome()
show_welcome()

Functions with Parameters — Giving Information In


Parameters let you pass information into a function. The function then uses that information to do
its job. This makes functions flexible and reusable.
func greet_character(character_name):
print("Welcome, " + character_name + "!")

# Now you can greet anyone:


greet_character("Amara") # prints: Welcome, Amara!
greet_character("Kwame") # prints: Welcome, Kwame!
greet_character("Zola") # prints: Welcome, Zola!

Functions with Return Values — Getting Information Out


A function can also calculate something and give you the result back. You use the return keyword
for this.
func calculate_damage(base_damage, strength):
var total = base_damage * strength
return total

# Using the function:


var damage_dealt = calculate_damage(10, 3)
print(damage_dealt) # prints 30

Godot's Special Built-In Functions


Godot automatically calls certain special functions at certain times. You do not call these yourself —
Godot calls them for you. The most important ones are:
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

Code What it means


func _ready(): Runs ONCE when the Node first appears
in the game. Use for setup.
func _process(delta): Runs EVERY SINGLE FRAME while the
game is running. Use for movement and
ongoing checks.
func _input(event): Runs whenever the player presses a
button or moves the mouse.
func _physics_process(delta): Like _process but synced to the physics
engine. Use for physics-based movement.

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

CHAPTER 8: ARRAYS — LISTS OF THINGS

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

Accessing Items in an Array


Every item in an array has a position number called an index. The index ALWAYS starts at 0, not 1.
This confuses many beginners at first.
var warriors = ["Amara", "Kwame", "Zola"]

print(warriors[0]) # prints Amara (first item)


print(warriors[1]) # prints Kwame (second item)
print(warriors[2]) # prints Zola (third item)

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.

Useful Array Functions


Code What it means
[Link](item) Add an item to the end of the array
array.remove_at(index) Remove the item at a specific position
[Link]() How many items are in the array
[Link](item) Returns true if the item exists in the array
[Link]() Remove all items from the array
[Link]() Sort the array from smallest to largest

var inventory = ["key", "torch", "map"]

[Link]("ancient_scroll")
print([Link]()) # 4
print([Link]("key")) # true

inventory.remove_at(1) # removes torch


print(inventory) # [key, map, ancient_scroll]

Looping Through an Array


This is one of the most common things you will do — going through every item in a list and doing
something with each one.
var chapters = ["The Awakening", "The Forest Trial", "The Ancient City"]

for chapter in chapters:


GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

print("Loading: " + chapter)


GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 9: DICTIONARIES — LABELLED INFORMATION

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
}

Accessing Dictionary Values


print(player["name"]) # prints Amara
print(player["health"]) # prints 100

# Changing a value:
player["health"] = 80
player["has_sword"] = true

# Adding a new key:


player["gold"] = 50

Useful Dictionary Functions


Code What it means
[Link](key) Returns true if the key exists
[Link]() Returns all the keys as an array
[Link]() Returns all the values as an array
[Link](key) Removes a key and its value
[Link]() How many key-value pairs exist

var character_stats = {
"name": "Kwame",
"strength": 8,
"speed": 5,
"wisdom": 10
}

print(character_stats.keys()) # [name, strength, speed, wisdom]


print(character_stats.has("gold")) # false — we never added gold
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 10: CLASSES AND NODES — BUILDING REAL


GAME OBJECTS

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.

The extends Keyword


The first line of almost every Godot script says extends followed by a Node type. This tells Godot
what kind of Node this script is controlling.
extends Node2D # This script controls a 2D Node
extends CharacterBody2D # This script controls a character that moves
extends Label # This script controls a text label
extends Control # This script controls a UI element

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.

A Complete Node Script Structure


extends CharacterBody2D

# Variables — the character's information


var health = 100
var speed = 200
var player_name = "Amara"

# Called when the scene starts


func _ready():
print(player_name + " is ready!")

# Called every frame


func _process(delta):
handle_movement(delta)

# Our custom movement function


func handle_movement(delta):
if Input.is_action_pressed("ui_right"):
position.x += speed * delta
if Input.is_action_pressed("ui_left"):
position.x -= speed * delta

# Our custom damage function


func take_damage(amount):
health -= amount
if health <= 0:
print(player_name + " has fallen!")
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

@export — Changing Values Without Editing Code


@export is a magic word that makes your variable appear in Godot's Inspector panel. This means
you can change values without touching your code at all — just click in the Inspector and type a
new number. Very useful for adjusting things quickly.
extends CharacterBody2D

@export var speed = 200


@export var health = 100
@export var character_name = "Amara"

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

CHAPTER 11: SIGNALS — HOW PARTS OF YOUR GAME


TALK TO EACH OTHER

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.

Using Built-In Signals


Godot Nodes come with built-in signals already made. You just need to connect them to a function.
extends Button

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.

Creating Your Own Signals


You can also create your own custom signals. This is very useful for story games where you want
one part of the game to tell another part that a story event happened.
extends Node

# Declare a custom signal


signal chapter_completed(chapter_number)

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

CHAPTER 12: BUILT-IN FUNCTIONS — FREE TOOLS FROM


GODOT

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.

print() — Showing Messages


print() displays a message in Godot's Output panel at the bottom. Use this constantly to check if
your code is working. It does not appear in the actual game — only in the editor.
print("Hello")
print(player_health)
print("Health is: " + str(player_health))

str() — Converting to Text


str() converts any value into a String so you can combine it with text. You need this whenever you
want to print a number alongside words.
var score = 150
print("Your score: " + str(score)) # prints: Your score: 150

int() and float() — Converting Numbers


var text_number = "42"
var real_number = int(text_number) # converts text to int: 42

var whole = 5
var decimal = float(whole) # converts int to float: 5.0

len() — How Long is This?


var name = "Amara"
print(len(name)) # 5 — five letters

var inventory = ["sword", "key", "map"]


print(len(inventory)) # 3 — three items

abs() — Absolute Value (Always Positive)


print(abs(-50)) # 50
print(abs(50)) # 50
# Useful for calculating distance regardless of direction

min() and max()


print(min(10, 5)) # 5 — returns the smaller value
print(max(10, 5)) # 10 — returns the larger value

# Common use: making sure health never goes above 100


player_health = min(player_health + 20, 100)

clamp() — Keep a Value Within a Range


# clamp(value, minimum, maximum)
player_health = clamp(player_health, 0, 100)
# health can never go below 0 or above 100
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

randf() and randi() — Random Numbers


var random_float = randf() # random number between 0.0 and 1.0
var random_int = randi() % 6 + 1 # random number between 1 and 6 (like a
dice)

get_tree() — Controlling the Game


get_tree().change_scene_to_file("res://scenes/main_menu.tscn") # change
scene
get_tree().quit() # exit the game
get_tree().paused = true # pause the game
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

CHAPTER 13: REAL GAME EXAMPLES — PUTTING IT ALL


TOGETHER

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.

Example 1: A Complete Dialogue System


This is the heart of any visual novel or story game. The player clicks to advance through dialogue
lines.
extends Node

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()

Example 2: A Health System


extends CharacterBody2D

@export var max_health = 100


var current_health = max_health

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")

Example 3: A Simple Save System


Saving the player's progress so they can continue later is essential in a story game.
extends Node

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

CHAPTER 14: QUICK REFERENCE SHEET — EVERYTHING


ON ONE PAGE

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)

for item in array: # loop through list


print(item)

while condition: # repeat until false


do_something()

Functions
func function_name(): # basic function
print("hello")

func with_param(value): # with parameter


print(value)

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

print(data["key"]) # access value


data["new_key"] = "new" # add or change
[Link]("key") # remove

Godot Special Functions


func _ready(): # runs once at start
func _process(delta): # runs every frame
func _input(event): # runs on input

Most Used Built-In Functions


print("message") # show in output
str(number) # convert to text
int("42") # text to int
len(array_or_string) # get length
clamp(value, min, max) # keep in range
randi() % 10 # random 0-9
abs(number) # always positive
get_tree().change_scene_to_file("res://[Link]")
GDScript Full Notes | For Godot 4 | Your African Game Developer Journey

A MESSAGE FOR YOU

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.

You might also like