getbetterat.work
Course 01

Learn GDScript.
Make Games Work.

GDScript is the coding language built just for the Godot game engine. It looks like Python, reads like plain English, and is the fastest way to make your game ideas real.

Fast to Write

You do not need to write long, messy code. GDScript uses simple words to get things done quickly.

Made for Godot

It connects directly to game pieces. Moving a character or playing a sound is just one line of code.

Easy to Read

It uses spaces and tabs to keep things neat. If you can read a recipe, you can read GDScript.

1. Variables: The Storage Boxes

Think of a variable as a box with a name on it. You can put information inside this box to use later. Every game needs to store things like the player's score, health, or name.

var player_health = 100
var score = 0
var player_name = "Hero"
var is_jumping = false

Rule: Always start with the word var to create a new box.

2. Functions: The Action Commands

A function is a list of instructions grouped together. Instead of telling the game how to jump every single time, you write a "jump" function once. Then, you just call its name.

func take_damage(amount):
    player_health = player_health - amount
    print("Ouch! Health is now ", player_health)

Rule: Start with func, name the action, add parentheses (), and end with a colon :.

3. If and Else: Making Game Choices

Games need to make decisions. If the player runs out of health, the game should end. If they grab a coin, the score should go up. We use If and Else for this.

if player_health <= 0:
    print("Game Over!")
elif player_health < 20:
    print("Warning: Low Health!")
else:
    print("You are doing great.")

4. How Scripts Talk to the Game

Godot games are built using "Nodes". Think of Nodes as physical parts: a character body, a camera, or a sound player. A GDScript is a brain that you attach to a Node to tell it what to do.

Player Node (Body)
Sprite (Picture)
Camera (Eyes)
GDScript (Brain)

The script at the bottom controls the whole Player Node.

5. The Game Loop: Ready and Process

There are two special actions that Godot calls automatically for you. You will use these in almost every game you make.

_ready()

This happens exactly once when the game starts. Use it to set up your game.

func _ready():
    score = 0
    print("Game Started")

_process(delta)

This happens every single frame (about 60 times a second). Use it for moving.

func _process(delta):
    move_player_forward()

6. Listening to the Keyboard

To make your game fun, the player needs to press buttons. GDScript has a simple tool called Input to check if a button is being pressed right now.

func _process(delta):
    if Input.is_action_pressed("move_right"):
        position.x = position.x + 5

Translation: "If the right arrow key is pressed, move the player 5 steps to the right."

7. Signals: Sending Messages

When an enemy dies, how does the score screen know to update? They use Signals. A Signal is like a doorbell. The enemy "rings" the doorbell when it dies. The score screen hears the bell and updates the number.

8. Fixing Bugs

Everyone makes mistakes when writing code. Godot has a built-in helper. When you tell Godot to print() something, it writes a message at the bottom of your screen. This helps you see what the code is doing.

Code you write:

print("Checking health...")
print(player_health)

What Godot shows you:

> Checking health...
> 100

9. Arrays: The Backpack

An Array is a single box that holds a list of items inside it. Think of it like a player's backpack. You use square brackets [] to create a list, and commas to separate the items.

var inventory = ["sword", "shield", "potion"]
print(inventory[0]) # This prints "sword"
Index 0
"sword"
Index 1
"shield"
Index 2
"potion"

Rule: In programming, we always start counting lists at exactly zero, not one.

10. Dictionaries: The Labeled Shelves

Sometimes lists are not enough. If you want to store a player's stats, it is better to label them. A Dictionary connects a "Key" (the label) to a "Value" (the data). You use curly brackets {}.

var player_stats = {
    "health": 100,
    "magic": 50,
    "speed": 12
}
print(player_stats["magic"]) # This prints 50

11. For Loops: Checking Every Item

If you have a backpack (Array) full of items, and you want to look at every single item one by one, you use a For Loop. It saves you from writing the same code over and over.

var backpack = ["apple", "key", "map"]

for item in backpack:
    print("You have a ", item)

The game will print out three lines automatically, one for the apple, one for the key, and one for the map.

12. While Loops: Keep Going Until Stopped

A While Loop will keep running the exact same code over and over again as long as a condition is true. Be careful! If the condition never turns false, the game will freeze forever.

var energy = 3

while energy > 0:
    print("Running...")
    energy = energy - 1
print("Tired.")

13. Export: Showing Variables to the Editor

Sometimes you want to change a variable (like player speed) without opening the code window. If you add the word @export to the start of a variable, Godot makes a little menu for it on the right side of your screen (The Inspector).

@export var speed = 200
@export var gravity = 9.8
Inspector Panel
Speed 200
Gravity 9.8

14. Vector2: Math for Movement

In 2D games, objects exist on a flat screen. You locate them using two numbers: X (left and right) and Y (up and down). In Godot, a Vector2 is just a package holding an X and a Y together.

var player_pos = Vector2(100, 50)

# Move right
player_pos.x += 10

# Move down
player_pos.y += 10

15. Comments: Notes for Yourself

Sometimes you write code today, but forget how it works tomorrow. You can write plain English notes inside your code that the computer will completely ignore. Just put a hashtag # at the start of the line.

# This function gives the player gold when they open a chest
func open_chest():
    gold = gold + 50 # Add 50 coins

16. Match: The Better If/Else

If you are checking the same variable against many different options (like what item a player is holding), writing "if, elif, elif, elif" gets messy. A Match statement is much cleaner.

var item_held = "sword"

match item_held:
    "sword":
        print("You deal damage!")
    "shield":
        print("You block the attack!")
    "potion":
        print("You heal up!")

17. Enums: Naming Your States

Instead of remembering if state "0" means standing still or state "1" means running, you can create a custom list of names called an Enum. It replaces boring numbers with words that are easy to read.

enum State {IDLE, RUNNING, JUMPING}
var current_state = State.IDLE

if current_state == State.RUNNING:
    speed = 200

18. Classes: Custom Blueprints

If you are making a game with lots of different enemies, you can write one script that acts as a master "blueprint". You give it a name using class_name. Then, other scripts can use this blueprint to make specific enemies like goblins or dragons.

# Save this as "enemy.gd"
class_name Enemy
extends Node2D

var health = 100

func die():
    queue_free() # This destroys the object

19. Three Rules for Beginners

1

Start Small

Do not try to make a massive 3D game on day one. Make a square move across the screen first.

2

Use the Built-in Help

If you hold CTRL (or CMD) and click on a word in your code, Godot will open a manual explaining what it does.

3

Tabs Matter

GDScript uses empty space (tabs) to know which code belongs to which function. Keep your edges lined up.