Understanding Basic Variables in GDScript: A Beginner’s Guide


Variables are fundamental building blocks in programming, and in GDScript, it’s no different. They allow you to store, manipulate, and use data efficiently. In this beginner’s guide, we’ll explore the basics of variables in GDScript, including data types, declaration, initialization, and usage.

Variables In GdScript

Table of Contents


Before we start, make sure you have Godot installed and a basic understanding of the GDScript language.

Variable In GDScript:

Data Types in GDScript:

GDScript supports several data types, including:

  1. int: Represents integers (whole numbers).
  2. float: Represents floating-point numbers (numbers with decimals).
  3. String: Represents text or a sequence of characters.
  4. bool: Represents Boolean values (True or False).
  5. Vector2: Represents a 2D vector with x and y components.
  6. Vector3: Represents a 3D vector with x, y, and z components.
  7. Array: Represents an ordered collection of elements.
  8. Dictionary: Represents a collection of key-value pairs.
  9. Object: The base class for most objects in Godot.

Declaring and Initializing Variables:

In GDScript, you declare and initialize variables as follows:

Variables In GDScript Explained
var integerVariable: int = 42
var floatVariable: float = 3.14
var textVariable: String = "Hello, GDScript!"
var booleanVariable: bool = true
var vector: Vector2 = Vector2(1, 2)
var myArray: Array = [1, 2, 3]
var playerData: Dictionary = {"name": "Player1", "score": 100}
var myObject: Object = preload("res://my_scene.tscn")

Variable Naming Conventions:

  • Variable names should start with a lowercase letter.
  • Use camelCase for multi-word variable names (e.g., myVariableName).
  • Variable names are case-sensitive.
Naming Conventions In GDScript

Using Variables:

# Access and update variables
integerVariable = integerVariable + 10

# Perform calculations
var result = floatVariable * 2

# Concatenate strings
var greeting = textVariable + " How are you?"

# Use conditional statements
if booleanVariable:
    print("It's true!")

# Access elements in an array
var secondElement = myArray[1]

# Access values in a dictionary
var playerName = playerData["name"]

# Interact with objects
var newObject = myObject.instance()


Variables are essential in programming and GDScript is no exception. They allow you to store and manipulate data, making your game logic dynamic and interactive. By understanding the basics of variables in GDScript, you’re well on your way to creating more complex and exciting games in Godot.