In GDScript, when I make typed variables or anything like that there's inconsistancy with the capitalisation and colour of the types. I'm curious if there's some nuanced difference between these, such as if it depends on if the type is hashable, iterable etc.?

There even seems to be slightly different shades of green, where Resource looks lighter than String. I confirmed this with a photo editing program. What is the meaning of this lol? If anyone could please share the underlying logic if it's there, otherwise I'll be fine memorising them. Thanks

  • Wow, I'd never noticed the slightly different shades of green. The aforementioned editor settings seem to have the red labeled "Keyword Color," the darker green "Base Type Color", lighter green "Engine Type Color," and an even lighter green labeled "User Type Color."

    So in the context of type hints, I think that roughly translates to red = primitives, darker green = collections (you can think of String as a collection of characters, Array and Dictionary seem to fall into this category as well), lighter green = engine-defined classes (Object and all its descendants), and extra light green = user-defined classes.

    In terms of capitalization I guess primitives are lowercase and anything more complex is capitalized?

The purpose of the colors is to make the code more readable.

You can configure most of it in Editor Settings >> General >> Text Editor >> Highlighting.

Wow, I'd never noticed the slightly different shades of green. The aforementioned editor settings seem to have the red labeled "Keyword Color," the darker green "Base Type Color", lighter green "Engine Type Color," and an even lighter green labeled "User Type Color."

So in the context of type hints, I think that roughly translates to red = primitives, darker green = collections (you can think of String as a collection of characters, Array and Dictionary seem to fall into this category as well), lighter green = engine-defined classes (Object and all its descendants), and extra light green = user-defined classes.

In terms of capitalization I guess primitives are lowercase and anything more complex is capitalized?

    The color settings are used in this source file:
    https://github.com/godotengine/godot/blob/3.5.1-stable/editor/plugins/script_text_editor.cpp

    For example:
    //colorize core types
    	const Color basetype_color = colors_cache.basetype_color;
    	text_edit->add_keyword_color("String", basetype_color);
    	text_edit->add_keyword_color("Vector2", basetype_color);
    	text_edit->add_keyword_color("Rect2", basetype_color);