CompiledFrog

Post #26: A GDScript Function

Today's post is very basic. GDScript supports functions!

Post26-Photo1_2026-06-18_compiledfrog

A function has a name and takes parameters. You "call" the function by its name, and pass the data to it, which are the "parameters". In the function above, the name is sum, and the parameters are num1 and num2. Notice num2 has a default value of 1, so if the call site only gives one argument, that would map to the first parameter, and the second would automatically be given the value 1.

Optionally you can "give back" a value from the function, which will be "returned" to the call site. In the example above, we are returning the mathematical sum of the two numbers.

Functions allow us to cleanly organize our code into "black boxes", hiding implementation details into relevant sections. Let me know how you use functions in your code!