Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | welltraman |
Hello,
Basically I want to do the same thing as how Node.get_node(NodePath path)
allows String
as an argument.
I want to allow my custom method to take arguments that are different from the expected arguments, but are convertible. (Since method overloading is not supported.)
Ultimately, what I’m hoping to do is, to allow:
Logger.warn("Error loading file!")
# instead of:
#Logger.warn(LogMsg.new("Error loading file!"))
When it’s expecting:
# Logger
func warn(m:LogMsg):
push_warning(m.compose("WARNING"))
# LogMsg
func _init(message:String):
_message = message
Is there any way this is possible?
Thanks.
I don’t quite follow. The parameter of the custom function needs to be a String
or something else? Since GDScript is dynamically typed, any data type supported can be passed to the custom function. So the function can be programmed to behave one way for String
input, or it could be programmed to behave for other input.
Ertain | 2021-10-16 09:15