![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | ChillFire |
Hello and good day to you,
so I was wondering why should I ever use the =
sign instead of the :=
sign when creating a variable, and my though process for that was :
- First I know that
:=
sets the type of the variable when assigning the value, meanwhile=
only assign the value to the variable - I am currently learning C in university(computer science degree) and I learnt C# in my off-time, so logically speaking I know that an
int32
takes less memory than anint64
, and afloat
takes less memory than adouble
- so I though that if I do not assign a type to my
var
in GDscript, does that mean the engine will allocate enough memory for any and all data types?
and so I came to the conclusion that I should always use :=
instead of =
since I am telling the engine that I’ll be using a single type for the variable, thus reserving just the required amount of memory for it, and in turn affecting the performance for the better. But I know that I am a beginner in GDscript so I came here to ask you fellow friends/seniors to help me and tell me why should I use the =
sign
TL;DR: :=
looks better than =
performance-wise since it assigns a single type to the variable and reduce error-chance, so why should =
be ever used when declaring a variable and what are some of it’s pros?