Skip to content

Static object field += value produces invalid GDScript (Variant.get("field") += value) #9

@senioritaelizabeth

Description

@senioritaelizabeth

uhmn

I’m trying to modify values inside a static variable defined in Haxe.
Haxe does not report any error during compilation, so the code appears valid on the Haxe side.
However, the generated GDScript throws an error in Godot when incrementing a field inside that static object.

Minimal example:

Haxe Source

class GlobalGame {
    public static var niz_stats = {
        hp: 60
    }
}

public function get_heal(heal:Int = 1):Void {
    GlobalGame.niz_stats.hp += heal;
}

GDScript... uh file?

var fh: Variant = GlobalGame.niz_stats
fh.get("hp") += heal   # ❌ Godot throws an error here

Godot does not allow using += on the result of get(), so this generated code is invalid.

Expected GDScript (valid)

Something like:

var fh = GlobalGame.niz_stats
fh.hp += heal

or:

var tmp = fh.get("hp")
tmp += heal
fh["hp"] = tmp

Current result:
Godot raises an error because it’s trying to perform += on the result of get(), which is not a settable value.

Expected result:
Valid GDScript that properly increments the field within the static object.

Additional notes:
– No errors appear on the Haxe compiler side.
– The issue only shows up once the code is translated to GDScript.
– Likely affects not only += but also -=, *=, /=, etc. (THEORETICALLY)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions