Skip to reading
Visual Scripting in Depth

44. Expose a GDScript helper

Edition 0.86.4.3

0.86.4.3 edition with revised lessons, updated cross-references and new cinematic/camera-safety supplements. Earlier examples, screenshots and registry figures retain their stated edition context.

Download PDFView PDF page

A small text helper can perform a calculation or an operation that is awkward to express in a graph. The graph then gives the rest of the author a friendly parameter form.

Code example
extends PCAScriptBase
Code example
func describe(amount, label):
    return {"amount": amount, "label": label}

1. Create a GDScript record, for example gd_tools. Enter the code above.

2. Open Functions as Nodes in that script editor. Add describe.

3. Give it a friendly name such as Describe a Reward.

4. Add amount as int with default 7, then label as string with default Workshop reward. Keep the order aligned with the code.

5. Use Definitions, apply the script changes and save.

6. Choose that function in a visual Call Script Function node and store its return.

The function name must match the source exactly. The display name can be friendlier. The definition does not change the code signature when you add or reorder parameters.

Use PCAScriptBase for PCA helpers and caller context. A custom extends declaration must inherit that base to use those facilities. Native Godot self continues to refer to the script object.

Page 48 of 93Permalink
Go to page