#Can't figure out how to pass classes/types as parameters

8 messages · Page 1 of 1 (latest)

stoic sparrow
#
func is_node_of_class(node: Node, class: ????):
  return node is class

Is there a way to pass Types/Classes as parameters ? If so what type would that be in itself ?

barren cedar
#

I think what you're looking for is the Variant type, also class is reserved so don't use it as a param name.

class A:
    var p = 123
    
func _ready():
    var a = A.new()
    test(a)
    
func test(my_class: Variant):
    return my_class is A
stoic sparrow
#

so that I given a class instance and a class, I can check if the instance is of a certain class (this is the simplified use case, I actually need it for more useful stuff)

barren cedar
#

Sorry I just realized what you wanted I think

stoic sparrow
#

I'm probably asking too much of the burgeoning type system

barren cedar
#

Yeah I don't think it is supported GD has a strange way of comparing two types. Like for comparing int types for example it looks like this:

print(typeof(value) == TYPE_INT)

Not sure how it would be done with custom classes

oak anvil