Description
Tested versions
Affected Godot Version
Godot Engine v4.4.1.stable.official [49a5bc7]
System Information
OS: Linux Mint 22.1 x86_64
Issue Description
When attempting to use the integer division operator (//) in GDScript to initialize a variable—either directly in the class scope or inside the _ready() function—the Godot editor reports a parsing error:
Expected expression after "/" operator.
The Godot editor displays the following error:
Error at (X, Y): Expected expression after "/" operator.
This occurs on the line where grid_size // 2 is used. The script cannot run due to this parsing error.
Workarounds and Notes
Re-typing the // operator: Did not solve the issue, indicating it's not caused by an invisible character or typo.
Moving the assignment to _ready(): While this is the correct practice for initializing @export variables, the error persisted in the line half_grid_size = grid_size // 2 inside _ready().
Using int(value / 2) as an alternative: Replacing half_grid_size = grid_size // 2 with half_grid_size = int(grid_size / 2) resolved the parsing error. The script compiled and ran correctly, although Godot still emitted an INTEGER_DIVISION warning (expected and can be ignored).
Impact:
This bug prevents the direct use of the integer division operator // in certain contexts, forcing developers to use alternatives like int(value / 2), which may be less intuitive for those accustomed to using //.
System information
OS: Linux Mint 22.1 x86_64 Godot Engine v4.4.1.stable.official [49a5bc7]
Issue description
.
Steps to reproduce
This error occurs even though the syntax is correct and the // operator is a standard feature of GDScript.
Steps to Reproduce
-
Create a new Godot project (version 4.4.1 or the affected version).
-
Create a new 3D scene.
-
Add a Node3D to the scene.
-
Attach a new GDScript (e.g., terrain.gd) to this Node3D.
-
Paste the following code into the script:
@export var grid_size: int = 5
var half_grid_size: int = grid_size // 2
func _ready():
print(half_grid_size)
Save the script.
Expected Behavior
The script should compile without errors, and the variable half_grid_size should be initialized with the result of the integer division of grid_size by 2 (in this case, 2).
Observed Behavior
Minimal reproduction project (MRP)
.