Skip to reading
Lua Scripting

Expose a Lua function as 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 PDF page

LESSON 17

Let an author set a puzzle's difficulty from the action editor.

Code example
local Script = {}
Code example
function Script.reward(tries, maximum)
    return math.max(0, maximum - math.max(0, tries - 1))
end
Code example
function Script.run(context)
    return Script.reward(3, 10)
end
Code example
return Script

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

Page 35 of 133Permalink
Go to page