What is a func? (please use beginner friendly explanation)

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

Hi i seem to encounter this specific type called func

What is it used for?
is it important?

:bust_in_silhouette: Reply From: dany_pitre

Hi there !
A func is short for a “function”.

it’s crutial in godot. In fact, it’s ont of the most important thing in this engine.

A function is something that you use to tell the engine to do something.

Here is an exemple. if i want my player to die when he touches an enemy. I will create the function die and i will call it when the enemy is touched. Then, all the code that is in my func die will be put to action.

it’s a really quick explanation, but I hope it helped a little.

:bust_in_silhouette: Reply From: deaton64


A function is a block of code that only runs when it’s called.
You can pass variables to and have variables returned from a function.
if you have some code that you need to run a number of times, instead of repeating the code, you put it in a function and call that.

You code will be a lot neater using functions.

Take a look at this GD Script Functions