Make a function appear as a node
CHAPTER 08 / FUNCTIONS AS NODES
A function is a named piece of script. Exposing it gives another designer a form it can call. We’ll use a two-line scoring function so every field has an obvious purpose.
func double_points(points: int = 1) -> int: return points * 21 Open a GDScript game script. Add the function above to an existing script or one named Signal Math. Its code name is double_points. It takes a whole number named points and returns a whole number.
2 Click Functions as Nodes. In Functions as Actions and Nodes, select double_points in the code-signature list and click Use selected code signature. Enable Expose as Action and Visual Node. Check Function Name, argument order, default 1 and return type int. Set Display Name to Double points.
The function definition. Its code name stays double_points even when its display name is Double points. The first parameter is points, an int.
3 Save the definition and use it. Click Use Definitions, then Apply Changes in the script editor and Save Project. Search for double_points in the reference. In an action list choose Double points, or use Call Script Function and pick it. Enter 3. If you want the result, select or supply a numeric result variable such as bonus. The expected value is 6.
