Why does this give me an error, yet work fine?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zlegacy

I have a script (Global.gd, loaded as GLOBAL) I autoload with some commonly used enums and constants. For example…

enum TYPES { WEAPON, EQUIPMENT, PLAYER, ENEMY, NPC }

I have a player scene and script. In my player script, I define a constant:

const TYPE = GLOBAL.TYPES.PLAYER

This shows an error below the editor, however, but works perfectly fine in game. The error reads : error (4,1) expected constant expression.

Seeing as how my game seems to work perfectly fine, is there something I am missing or should be concerned with? Is this just a bug or am I really misusing constants and enums together?

It could be that, since the PLAYER variable is already global, you don’t need to declare it as TYPE = GLOBAL.TYPES.PLAYER; you can just declare it as const var TYPE = PLAYER.

Ertain | 2018-12-25 06:11