+1 vote

I'm just learning my second programming language with godot, so applying my knowledge is kinda hard right now.

Does GDScript offer the same polymorphism as c#/++?

Godot version v3.3.2.stable.official
in Engine by (20 points)

1 Answer

+1 vote

Yes. This can be implemented by using a FuncRef

  • First create a method that will be called with the "callback" (In different programming languages: Completion/Block/Closure/... etc.)

func completion_method():
    pass # To do something
func completion_method_with_params(p1: String, p2: int):
    pass # To do something 
  • Then create a method that will receive our "callback"

func some_method(completion: FuncRef, completion_with_params: FuncRef):
    # To do something
    # To do something
    completion.call_funcv(["kurtsev", 0103])
    # To do something
  • And now create a reference to the "callback" and just pass it to the method

var completion = funcref(self, "completion_method")
var completion_with_params = funcref(self, "completion_method_with_params")
some_method(completion, completion_with_params)
by (158 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.