How to use enum as argument in funtions?

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

HI, when I am using interpolations on Tween nodes last 2 arguments apeaar as enum values, I am interested in how to do that, I know it is not necessary, I could pass an enum value in func call but, this is most comfortable especially when func is called outside the original script

Enums in Tween arguments


enum items {sword, shield}


func equip(item = items): # dosen't work as tweens
:bust_in_silhouette: Reply From: Inces

You just need to have a class of a node with those enums.

extends RigidBody2D
class_name Player
enum items {sword,shield}

From that moment You can call from everywhere in the script :


Hi, maybe I wasn’t clear at all, I know how to use an enum, I was asking how to show a list of enum’s values when I set arguments in a call func that use them. Even using class_name that list didn’t appear, do you have an example in func build?

Covenauta | 2022-03-10 23:01

Introducing a class to system is all it takes to show its enum list from everywhere You call. Once You create a class using class_name Godots compiler shows it in a node list and autocompletes in editor. In example above I created Player class. Now I can start writing in random script “Pl” and editor will autocomplete “Player”. Now if I input dot : “Player.” compiller will show every function and every enum of Players script, including .sword and .shield. It works the same way as You use Tween.TRANS_BACK

Inces | 2022-03-11 15:18

Okey, now I understand a bit more about Godot thanks for it, I didn’t know how class_name really works, but look this

I set class_name

extends KinematicBody2D
class_name Player

now it works as you said everywere, thanks


but as you can see in the pictures I did not write Tween. I came to the last 2 arguments and automatically appear a list that includes tween.enum’s values, I am sure there is someting on this func to show a specific enum automatically in that argument, only for wirte “,” before is needed the enum

enter image description here
enter image description here

this is not happening when I use equip(), then I realise something


but I haven’t success


you reserve a vote for your time, I will try to be more specific on my questions, have a good day.

Covenauta | 2022-03-11 20:09

Aaah ok I finally understood what You meant :stuck_out_tongue:
I did some digging and found article covering that :
Static typing in GDScript — Godot Engine (stable) documentation in English

unfortunately, it specifically says, that it is impossible to cast enums in Godot :(. That means compiler can’t be informed about variable being enum, and it will never autocomplete like built_in Tween enum :confused:

Inces | 2022-03-11 21:19

Hooo well, thanks for it, even it is impossible I learned some useful things, take your best answer!

Covenauta | 2022-03-11 22:15