How to add Optional Typing to Function Argument when type is defined in a different script?

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

I have a singleton, Global.tscn
In the singleton, I have enum DotType

In any other script, I want to create a function with an argument of type DotType
Something like this:
func FooBar(dotType : DotType)

This doesn’t compile as DotType can’t be found.
I have also tried:
func FooBar(dotType : Global.DotType)
This gives a similar error:
couldn't be found on base Global.gd

Any ideas how to do this?

:bust_in_silhouette: Reply From: lariscy

I ran into this same issue recently and found this reddit article showing that Enums are basically seens as ints so you can instead do something like this:

enum Myenum { A, B, C }

func myfunc(value:int):
    print(value)

func _ready():
    myfunc(Myenum.A) # will actually send `0`
    myfunc(Myenum.B) # will actually send `1`