Skip to reading
Action Lists & Events

28. Publish a function with editable parameters

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

Functions as Nodes turns existing script functions into selectable actions with a parameter form. It is useful when the same operation is needed with different values, such as awarding different numbers of points.

Code example
func reward(points: int, message: String) -> Variant:
    await AddScore({"amount": points})
    await ShowMessage({"text": message, "duration": 2.2})
    return true

1. Write and validate the function in a supported text script.

2. Open Functions as Nodes, then Add Function. Enter the exact function name reward and a friendly display name.

3. Add points as int and message as string, in the same order as the code. Choose sensible defaults.

4. Keep Expose as Action and Visual Node checked. Choose Use Definitions, then Apply Changes in the script editor and save.

5. In an action list or graph, choose Call Script Function, select the published function, and fill in its named parameters.

Use Definitions accepts the metadata in that dialog; it does not run the function or rewrite its source. If the function takes points and message, the definition must describe those parameters. A Result Variable can receive the returned true value, but an ordinary list will not automatically branch on it.

For visual functions, publish an existing entry node and use a Return node for a result. Named parameter expressions use $param. Removing the entry node or disabling exposure can invalidate an already authored function call.

Page 32 of 189Permalink
Go to page