godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Variables declared with static type hints initialize differently depending on type

Open bfedie518 opened this issue 3 years ago • 0 comments

Godot version: 3.5

Issue description: When declaring variables, the variable is initialized. When not using static type hints, variables are initialized as null. If a static type hint is given, but an initial value is not, the engine chooses a value based on the type. This behavior is not documented.

Examples: Assume the user has defined CustomClass elsewhere with class_name CustomClass.

var a
var b: int
var c: Vector2
var d: CustomClass

Is equivalent to:

var a = null
var b: int = 0
var c: Vector2 = Vector2.ZERO
var d: CustomClass = null

Relevant documentation pages: This behavior should be noted on the Static typing in GDScript page. Additionally, each built-in type/class's page (int and Vector2 in the above example) should state what they initialize as when declared with a static type hint.

Note: I haven't tested this behavior with Godot 4.0-Alpha, but the latest documentation on static typing doesn't mention it either.

bfedie518 avatar Sep 06 '22 17:09 bfedie518