+1 vote

in some methods after the brackets "()" there is a sign or what ever you call like this: " -> void" so can any body help me know what does it mean?

in Engine by (282 points)

1 Answer

+3 votes
Best answer

The return type "void" means that no value is returned. If we capture the return value of such a void function, it will be Null, just like when no return value is specified and no return type is specified either.

func foo() -> void:
    pass
func bar():
    pass
var result = some_object.foo()
print(str(result)) # will print "Null"
result = bar()
print(str(result)) # will print "Null" again

In other languages, trying to capture the return value of a void function would result in an error at compile time, but script languages can be a bit different and more flexible.

IMO using " -> void:" is a way to communicate that no return value is forthcoming. You also can't have a "return value" statement in such a function in GDScript.

by (210 points)
selected by

https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/static_typing.html
ya, just being explicit about types which is not required but can expose some errors and warnings sometimes

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.