I’m am not much of a Godot guy, but I want to make sure this question gets answered, here is what I found:
In Godot, you can declare functions in any order within a script because the script is parsed before execution. This allows you to define functions after the point where they are called. When the script is parsed, all the function definitions are collected, and they become available for use throughout the script.
In your example, when the _ready
() function is called, it will search for the test()
function and execute it if it exists. The fact that the test()
function is declared after the _ready()
function does not generate an error because the parser has already scanned the entire script and knows about the existence of both functions.
This behavior is possible due to a process called “forward declaration.” When the script is parsed, the parser scans the entire script to gather information about the functions, signals, and variables used. As a result, it knows about the existence of all the functions before the execution begins.
In some programming languages, forward declaration is necessary to use a function before it is defined. However, in Godot’s scripting language, GDScript, forward declaration is not required because the script is parsed before execution, allowing functions to be called regardless of their position within the script.