0 votes

I'm following the GDQuest course Tactical RPG, and I see that :
export var size := Vector2(20, 20)

I searched through the doc and internet but I couldn't find what it meant. Any idea ?

in Engine by (22 points)

2 Answers

+4 votes

As far as I know := means, in this case, the same as var varname : Vector2 = Vector2(0, 0)
Basically := assign type of variable to it.
Another example can be:
var somevar := 1 will mark variable as int
var somevar := 1.0 will mark var as float
var somevar := true will mark var as bool
Etc etc. You get the point. Sorry for lack of formating. Was typing from phone.
Best regards.

by (85 points)
+1 vote

As explained in another answer the := is a way of forcing a variable to only take on values of a certain type (such as bool, int, float, String, Vector2, Array, etc).

Since that's already been explained I'd like to add that there are two primary reasons for using typed variables.

Reason #1 is that it helps catch coding errors, and makes code more understandable (albeit also longer).

Reason #2 is that it allows the engine to run more efficiently, since the engine knows beforehand what type of data each variable will definitely be.

by (180 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.