5. Values, types and conversions
| Type | Example | Typical use |
|---|---|---|
| bool | true, false | Puzzle flags |
| int | 3 | Counts, indices |
| float | 2.5 | Seconds, speeds |
| String | "Archive" | Speech, IDs |
| StringName | &"idle" | Frequently repeated names |
| Vector2 / Vector3 | Vector3(2, 0, -1) | Positions and directions |
| Color | Color("88bbff") | Colors |
| Array / Dictionary | [1, 2], {"open": true} | Containers |
| Object / Node / Resource | An instance of a class | Godot objects |
| Variant / null | Any value / no value | Dynamic values and missing results |
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.
