How to use default godot enums?

Godot Version

3.6

Question

Hi, I have very dumb question, sorry, but how to use godot builtin enums? Let’s say I want to get MATH_CONSTANT_SQRT2 constant, so I’ve tried:

func _ready():
	print(VisualScriptMathConstant.MATH_CONSTANT_SQRT2)

But I’m gettin 5 for some reason, how i can get actual value?

I would guess there are fewer constant in GDscript than in the visual scripting, you may have to make your own constant const s2 = sqrt(2)

1 Like

So, an enum is, essentially, an int with different names for its values. It is not the same as a constant. Some languages let you attach some other constant value to each enum value, but GDScript does not (that is not what an enum is for). So, 5 is in fact the actual value (presumably MATH_CONSTANT_SQRT2 is the fifth value defined in this particular enum).

Now, that doesn’t help you very much, because you don’t really care what order these values were defined in, you want to know the square root of 2 (or at least a decent approximation). As far as I can tell from the VisualScriptMathConstant documentation, that must be defined somewhere else - this enum is only for selecting different kinds of ports for visual scripts. I’d guess that if you’re creating a new visual script node, you can give it a port that outputs the square root of 2 (approximately), but you can’t access that value in code, at least not via VisualScriptMathConstant alone.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.