Skip to reading
GDScript Programming & Godot

5. Values, types and conversions

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Source table from 5. Values, types and conversions, page 13
TypeExampleTypical use
booltrue, falsePuzzle flags
int3Counts, indices
float2.5Seconds, speeds
String"Archive"Speech, IDs
StringName&"idle"Frequently repeated names
Vector2 / Vector3Vector3(2, 0, -1)Positions and directions
ColorColor("88bbff")Colors
Array / Dictionary[1, 2], {"open": true}Containers
Object / Node / ResourceAn instance of a classGodot objects
Variant / nullAny value / no valueDynamic values and missing results
Code example
func run() -> Array:
    var count: int = 3
    var seconds: float = 0.5
    var title := "Parts tray"
    var converted: int = int("12")
    return [count, seconds, title, converted]

var title := "Parts tray" infers a String type. var title: String = ... states the type directly. A variable without a type can hold different kinds of values. When a helper returns Variant, use an explicit Variant or a deliberate cast rather than forcing unsafe inference.

GDScript names are case-sensitive. points, Points and POINTS are three names. Text-to-number conversions need validation when input can be malformed. A nonempty string is not a reliable way to parse a player’s yes/no answer.

Page 13 of 378Permalink
Go to page