I don't understand what's the method for passing args in this function ( func blabla(arg: Vector2) -> Vector2: )

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

I’m following the Tactical RPG GDQuest course and I see this func :

func calculate_map_position(grid_position: Vector2) -> Vector2:
    return grid_position * cell_size + _half_of_cell_size

I don’t understand what’s going on in the arguments. Why “grid_position: Vector2” ? If the func takes a Vector2, shouldn’t it be just written “grid_position” ? And, it’s not a default assignement right ? default should be written with “=”, and it should be a value not a type. And then why does after the parenthesis’s closed there’s “-> Vector2” ? It’s not an argument, I didn’t even know you could write stuff after passing an argument, so what is it ? And why is it Vector 2 ? My guess is that it’s all to make sure the taken value and the return value are both Vector2 no matter the case, but I don’t know for sure, I don’t know what I’m actually telling the computer to do, and I can’t find any info in the Docs or FAQ or Python synthax it’s so frustrating ! >_<

I thank you in advance for any info you can share regarding my questions and/or for pointing me to where I should be searching when looking for this kind of information :).

:bust_in_silhouette: Reply From: USBashka

These things are typehintings and the syntax is exact the same as in Python. The : Vector2 after variable name tells that it should be Vector2. And -> Vector2 shows the type function returns.

:bust_in_silhouette: Reply From: omggomb

In addition to the other answer:

The Godot documentaion has a page on static typing: