Skip to reading
Actions, Properties & Runtime Updates

Make a function appear as a node

Edition 0.86.4.4 Hotfix 2

Updated through 0.86.4.4 Hotfix 2, with cinematic property, recorded-pose or voice-timing lessons as described in this guide. Earlier examples, screenshots and complete registry figures retain their stated edition context.

Download PDFView illustrations

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.

Code example
func double_points(points: int = 1) -> int:
Code example
    return points * 2

1 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.

Page 14 of 39Permalink
Go to page