This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 "gridposition: Vector2" ? If the func takes a Vector2, shouldn't it be just written "gridposition" ? 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 :).

Godot version 3.4.4 (stable)
in Engine by (22 points)

2 Answers

+1 vote

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.

by (654 points)
+1 vote

In addition to the other answer:

The Godot documentaion has a page on static typing:
https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/static_typing.html

by (1,519 points)
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.