Static Typing

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

Hello. I have doubts regarding the static language in the Godot engine.

var numero : int  = 5

I understand that above I have the variable called “numero” and that throughout the game, it will have an integer value (5), right? good. But what if I just do this?

var numero : int

What value does the variable “numero” have? Does it initialize itself? Now, thinking that this is the case and that it will have a value of zero, I have no problem. But what about this?

var camara : Camera

What value does this variable have? or how can i initialize it?

Why am I asking this? I’ve seen some examples where they show this:

var scene:PackedScene = load("resources//... etc")

I understand this part:

var scene:PackedScene

But I don’t understand this part anymore:

= load("resources//... etc")

Does this part initialize the variable? But what if it doesn’t initialize at first? Then how do I initialize it?

But what if it doesn’t initialize at first? Then how do I initialize it? I can do this?

scene =  load("resources//... etc")

Thanks for your help.

after load or preload, you’ll still need to instance and add it. the typing just makes it harder for you to make inconsistencies in your code that may lead to errors in large projects. just a real strict code checker… apparently it does improve the performance and improves code completion and other stuff…

CassanovaWong | 2023-03-22 12:56

:bust_in_silhouette: Reply From: codabase

Hi there! You’ve inspired me to write an article about this topic to help others as well, please check out the answer here and let me know if it was helpful! I’m happy to help with more questions any time if this was valuable to you.

I really appreciate your valuable response and above all that you have taken my question, to make your fabulous tutorial!

Thanks very much friend!

javier | 2023-03-22 03:49

I’m glad it helped! Good luck with your game development journey and I hope you make an awesome game you are proud of :slight_smile: Cheers!

codabase | 2023-03-22 05:05