Skip to reading
PCA Script Programming

32. Make a function into a visual node

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView illustrations
Code example
global score = 0
function award(points: integer, message: text = "Well done."): integer
    score += points
    log(message)
    return score
end

1. Create a PCA Script with ID rewards_pca, enter this function, Validate and Apply Changes.

2. Click Functions as Nodes. Add/select the award definition. Its function name must match the source exactly in meaning, and its parameters must match the source order.

3. Add the parameters manually in source order: points as int, then message as string. Enter defaults of 5 and Well done. The definition UI uses int/string where the PCA source uses integer/text. Use Definitions accepts this metadata; it does not scan the source, create the function or run it. Then Apply Changes to save the script.

4. In a visual script, add Call Script Function. Choose the published script/function and fill in points and message. Choose a result variable if you need the returned score.

5. The same published function can be used from an action list that exposes Call Script Function. Test one call with 5 points and a second with 0 so you can confirm the return and side effects.

Changing a source signature later does not magically repair every existing node’s saved parameter mapping. Update the exposed definition and revisit callers. If you click Use Definitions with no functions added, you have accepted an empty list. Nothing will appear in Call Script Function until you add and save a definition.

Figure 12. A visual function-call node exposes the published parameters as editable fields.

Page 40 of 357Permalink
Go to page