Godot: export doesn't work with enums from another script/class

Created on 21 Jun 2018  路  13Comments  路  Source: godotengine/godot

neither of the following work, where g is set to autoload

export var type = g.BMW
export(g.Type) var type = g.BMW

gives error:

built-in:7 - Parse Error: invalid index 'BMW' in constant expression
modules/gdscript/gdscript.cpp:583 - Method/Function Failed, returning: ERR_PARSE_ERROR

this works tho':

var type = g.BMW

See attached project
godot-dbg.zip

edit
although it seems that if you close&reopen the project (possibly the scene, didn't try that one) the error disappears so you might have to recreate from scratch the simple project I attached.

bug gdscript

Most helpful comment

This also seems to happen with built-in enums.

export (Tween.TransitionType) var transition_type := Tween.TRANS_CUBIC

gives me the error

invalid index 'TransitionType' in constant expression

All 13 comments

On master or 3.0.3? Or both?

Isn't this the same as #14681?

Didn't cross my mind to search through closed issues. The version is master a9acdd8

I found something perhaps related. Like the above, g is a singleton script and doing something like

export(g.EntityType) var type setget _set_type

triggers the setter with a null value in all cases (before the children nodes etc. are ready).

In my script I have

export(g.EntityType) var type setget _set_type

func _set_type(val):
    # I'm forced to use this otherwise game crashes, even if I don't set `type` anywhere
    # in the script or inspector, it gets called by itself with `val = null` when
    # $Pattern (in this case) isn't present in the scene tree
    if val == null:
        return

    var type = val
    $Pattern.entity_type = type

edit
was just pointed to this issue #17436 that describes setters being triggered on load, which I though in the above is due to enum explicitly but it seems it's more generic

Confirmed - still an issue as of 3.1 alpha 4.

Sorry to bother you but, was this released with the v3.1.beta3.official?

In said version, it doesn't seem to work properly yet. But I don't know if this commit was included in said version or if it will be included in the following one?

The fix was included in 3.1 beta 3, but the bug is indeed still reproducible in the current master branch (5fa5678).

This also seems to happen with built-in enums.

export (Tween.TransitionType) var transition_type := Tween.TRANS_CUBIC

gives me the error

invalid index 'TransitionType' in constant expression

Another MRP from #26537:

Confirmed in 49d82f2:

SCRIPT ERROR: GDScript::reload: Parse Error: invalid index 'TEXT_SPAM_BASIC' in constant expression
   At: res://Node2D.gd:3.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.

Interestingly, it actually works fine when you run the game.

MRP: New Game Project.zip

Still happens to me?
image

@that-richard: I believe this was a fix for GDScript, not c#

@that-richard: I believe this was a fix for GDScript, not c#

That is GDScript, I just have an external editor (VSCode) :D

Hi, this issue suddenly happens in my 3.2.2
And restarting Godot doesn't fix this either...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gonzo191 picture gonzo191  路  3Comments

blurymind picture blurymind  路  3Comments

ndee85 picture ndee85  路  3Comments

SleepProgger picture SleepProgger  路  3Comments

nunodonato picture nunodonato  路  3Comments