+1 vote
asked Nov 25, 2019 in Engine by SacrificerXY (22 points)

2 Answers

+1 vote
Best answer

Lines with green number means the editor's script analysis succeeded in detecting the type of all things in that line, so it can give accurate completion and checks.

When the line number is grey, it means the editor was not able to fully analyse the line (i.e it doesn't know in advance the type of some variable in it) so completion may not be 100% accurate.

This is the concept of "Safe Lines", see https://godotengine.org/article/optional-typing-gdscript

answered Nov 26, 2019 by Zylann (27,004 points)
selected Nov 28, 2019 by SacrificerXY
0 votes

Short version:

It's all to do with Static Typing (a 3.1 feature).

Grey lines numbers indicate Unsafe Lines, where the editor doesn't know if the code will work at runtime. Green line numbers indicate that you have used Static Typing to help casting. See the section headed Safe lines on this page

Long version:

Godot 3.1 introduced Static Typing, which you can read about here

What that means is that, when creating a variable, you can tell Godot whether it's an integer, float, text, vector, class etc. The type can be a built in, a core class or even one of your own custom classes. Although I said that this works for variables, it also works for parameters, function return values etc.

You don't have to use Static Typing and can carry on just letting Godot use Dynamic Typing, if you wish.

One of the things about types is that, if you try and convert one type to another (eg integer to float), It may or may not be a "safe" conversion. The Godot team call that conversion "casting".

Quite often, Godot won't know until runtime whether the casting can be done, since it depends on what you put in a variable. In such cases, the editor warns you that the casting is unsafe. Unsafe lines are those defined as those where there may be a casting problem when you run the code and the line number is grey. If you explicitly state types, then the casting will work and the line number is green.

You can chose to turn safe lines on/off or change their colour in the editor settings (Text Editor –> Highlights)

answered Nov 26, 2019 by Beechside (33 points)
edited Dec 12, 2019 by Beechside
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 How to use this Q&A? before posting your first questions.