BLINKCADEAI GAME DEVELOPMENT
Sign In
Class GS-110 3 of 18

GDScript Essentials

Variables and explicit type annotations

Variables and explicit type annotations is class 3 of GDScript Essentials. Create a small Godot project and type the example yourself in the Script workspace. Do not paste blindly: run after each meaningful change.

Browser-first class 40 minutes Godot runtime lab
GS-110 Class 3 of 18
1LearnUnderstand the idea 2BuildCreate it in Godot 3PracticeRun and change it 4ProveCheck understanding

Variables and explicit type annotations

Variables and explicit type annotations is class 3 of GDScript Essentials. Create a small Godot project and type the example yourself in the Script workspace. Do not paste blindly: run after each meaningful change.

By the end of this class, you can…

  • Explain variables and explicit type annotations in the context of a Godot project.
  • Create a focused Godot demonstration of variables and explicit type annotations using the instructions and examples on this page.
  • Verify the result, diagnose a likely failure, and make one independent change.

Key ideas

Variables and explicit type annotations

The class focuses on variables and explicit type annotations as a practical part of GDScript Essentials.

Observable result

Every change should produce something you can see in the running game, Inspector, Output panel, debugger, or profiler.

Small test

Isolate one idea before combining it with the larger course project. Small scenes are easier to understand and repair.

Before you begin

  • Godot 4.7.2 Standard installed for native-editor activities. The lesson text and project construction steps are entirely on this webpage.
  • A writable local folder for a small personal practice project.
  • The Output panel visible and Run Current Scene available so each change can be tested immediately.

Create the feature

Scene tree

LessonRoot (Node)
└── ResultLabel (Label)

Files and purpose

  • res://scenes/class_03.tscnThe small practice scene you create from the steps on this page.
  • res://scripts/class_03.gdThe typed GDScript for this class activity.
  1. 1

    Open Godot 4.7.2 Standard and create or open a practice project named “gs_110_practice”.

  2. 2

    Create a new Node scene, name the root “Class03”, and save it as res://scenes/class_03.tscn.

  3. 3

    Recreate the scene tree shown on this page using built-in nodes. External lesson assets and downloaded project files are not required.

  4. 4

    Create res://scripts/class_03.gd, attach it to the root, and type the example or configuration shown below.

  5. 5

    Implement the focused activity for “Variables and explicit type annotations”. Run the current scene after each meaningful change and watch the Output panel for errors.

  6. 6

    Perform the verification test, then make the independent variation. Record the result in the notes field before marking the class complete.

GDScript and explanation

Type the code yourself, then change one value or behavior so you can see cause and effect.

GDSCRIPT

Typed gameplay values

extends Node

func _ready() -> void:
    var player_name: String = "Nova"
    var score: int = 250
    var has_key: bool = true
    print("%s | score: %d | key: %s" % [player_name, score, has_key])

Each variable has a name, a type, and a value. Godot can warn when later code tries to assign an incompatible value.

Expected result

The practice project demonstrates “Variables and explicit type annotations” with no parser error, and the result is visible in the running scene, Inspector, Output panel, debugger, or profiler as directed.

Write, check, and run the code

Keep the player name as Nova, change score to 250, and set has_key to true without removing the type annotations.

Common mistakes

The class scene runs but nothing appears to change.

Likely causeThe wrong scene may be running, the script may not be attached, or the result is only printed in the Output panel.

FixUse Run Current Scene, select the root node to confirm the script property, and keep the Output panel visible.

Godot reports an identifier, indentation, or type error.

Likely causeGDScript is indentation-sensitive and typed declarations must match the assigned value.

FixStart with the first error line, compare punctuation and indentation with the on-page example, then run again before changing anything else.

The example works once but breaks after a variation.

Likely causeThe variation changed more than one assumption at the same time.

FixUndo to the last working state and reapply one small change at a time while recording the observed result.

Make it your own

Change one meaningful condition, value, node relationship, or input in the “Variables and explicit type annotations” example. Predict the result before running, then compare the prediction with what Godot actually does.

Check your understanding

01What observable evidence proves that “Variables and explicit type annotations” is working?

The exact evidence depends on the class, but it must be visible or measurable in the running scene, Inspector, Output panel, debugger, profiler, or produced release artifact.

02Why does this class use a small practice scene instead of a large game?

A small scene isolates the concept, reduces unrelated failures, and makes it easier to repeat a test and understand cause and effect.

03What should you do before marking the class complete?

Run the verification, complete the independent variation, fix blocking errors, and explain the result in your own words.

You are ready to continue when…

  • You created the class scene and script from the instructions on this webpage without a course download.
  • The practice project demonstrates “Variables and explicit type annotations” with no parser error, and the result is visible in the running scene, Inspector, Output panel, debugger, or profiler as directed.
  • You completed the independent variation and can explain why the result changed.

Class glossary

Scene
A saved tree of nodes that can represent a screen, character, system, level, or reusable object.
Node
A focused Godot object that provides behavior and can be arranged in the scene tree.
Typed GDScript
GDScript with explicit or inferred static types that improve editor assistance and catch more mistakes before runtime.

Private learning notes