+2 votes

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 (291 points)

1 Answer

+4 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:
func bar():
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 (244 points)
selected by

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 Frequently asked questions and 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 [email protected] with your username.