Expose a Lua function as a visual node
LESSON 17
Let an author set a puzzle's difficulty from the action editor.
local Script = {}function Script.reward(tries, maximum)
return math.max(0, maximum - math.max(0, tries - 1))
endfunction Script.run(context)
return Script.reward(3, 10)
endreturn Script1. Apply archive_score. Open Functions as Nodes and add a definition with the exact source name
reward and the display label Archive Reward.
2. Add two int parameters in order: tries with default 1, then maximum with default 10. Enable
Expose as Action and Visual Node. Choose Use Definitions, then Apply Changes and save.
3. Add Call Script Function to a visual graph or supported action list. Choose Archive Reward, enter
3 and 10, and select a numeric result variable. Trigger the action. The result should be 8. A first try
should return 10.
Use Definitions accepts the metadata you entered. The Lua source provides the implementation. If the
picker is empty, reopen the record and compare the saved function name, enabled state and parameter
order.
