what does -> void mean

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mdubaisi

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?

:bust_in_silhouette: Reply From: tuon

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.

Static typing in GDScript — Godot Engine (stable) documentation in English
ya, just being explicit about types which is not required but can expose some errors and warnings sometimes

rakkarage | 2020-08-15 20:03