Numbers & comments
🧮 Printing Your First Number with GDScript
In this part of my beginner journey with GDScript, I explored something fundamental—numbers and how to print variables to the console.
🧠 Back to Basics: What Computers Do
Before anything else, it helps to remember: computers are just really advanced calculators. So naturally, learning how to work with numbers is one of the first steps in programming.
In Godot (using GDScript), numbers come in two main types:
int
(integers, like1
,42
)float
(decimal numbers like3.14
or0.5
)
✍️ Writing Our First Variable
We used the var
keyword to create a variable and store a number:
func _ready() -> void:
var num_1 = 1
This line creates a variable called num_1
and stores the integer 1
in it. GDScript figures out the type automatically—no need to specify it explicitly.
🖨️ Printing It to the Console
To see the value, I printed a message:
func _ready() -> void:
var num_1 = 1
print("Hello number int:", num_1)
That comma is important! It separates the text (a string) from the variable. Without it, Godot would throw an error.
🔕 Cleaning Up the Console using Comments
Previously, my _process(delta)
function was spamming the console with “Refreshing…” every frame. To keep things clean, I commented that out using #
and replaced the _process()
function with a simple pass
.
func _process(delta: float) -> void:
#print("Refreshing...", delta)
pass
With that fixed, running the project cleanly printed:
Hello number int: 1
💡 What I Learned
- Variables in GDScript can store numbers using
var
. print()
helps you check the value of variables.- Use commas in
print()
to combine text and data. - You can “silence” a function using
pass
. - Comments (with
#
) are handy for disabling code temporarily.
This may be a small step, but it’s a huge part of learning how code interacts with your game’s logic. Next, I’ll look into floats, math operations, and how to start using these numbers inside real gameplay logic!