what is the difference between using ":" , "=" and ": =" for variables

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Özgür

I miss some basic knowledge that i should probably need to known and this is one of them
so in tutorials when they creating variable for Vector2 i see they are using different punctuations . Some time they are using both of them at the same time and they are like this:

var velocity = Vector2.ZERO
var velocity : Vector2
var velocity: = Vector2.ZERO

Could you guys explain it to me difference between this three ways when creating variables ?

:bust_in_silhouette: Reply From: klaas

Hi,

var velocity = Vector2.ZERO

the variable velocity is a variant and can take any kind of type. now you set it to a zero vector2

var velocity : Vector2

the varibale velocity is declared as Vector2, it can only take Vector2 values

 var velocity: = Vector2.ZERO

godot should guess the declearation of the variable velocity by this assignment. It will declare it as Vector2 because the assigned value is of this type

You are awesome man. Thanks for explaining this to me

Özgür | 2020-10-03 17:57