Title here
Summary here
In GDScript, variables are dynamically typed, but you can optionally specify their types for stricter type checking.
extends Node
func _ready():
# var declares a variable
var a = "initial"
print(a)
# You can declare multiple variables at once
var b = 1
var c = 2
print(b, " ", c)
# GDScript infers the type of initialized variables
var d = true
print(d)
# Variables declared without initialization are null
var e
print(e)
# In GDScript, there's no special syntax for short declaration
# You always use 'var' to declare variables
var f = "apple"
print(f)
To run this script in Godot:
The output will be:
initial
1 2
true
null
apple
In GDScript:
var
keyword.var b: int = 1
.null
by default.var
.print()
for console output instead of a separate package.GDScript is designed to be simple and easy to use, especially within the context of the Godot game engine. Its syntax is inspired by Python, making it quite different from statically typed languages.