Learn Lua · Your first CoCoCo script · Lesson 1 of 3
Input and output
Every lesson so far has used the shape of a real CoCoCo script. In a workflow script
node, CoCoCo passes in what the node before it produced, and passes what you return
to the nodes after it:
-- A workflow script node: input in, a value out.
local input = ...
return { orderId = input.orderId, lineCount = #input.lines }Other places scripts run receive their data in different ways; Where scripts
run lists them all. The shape here, local input = ...
then return, is the most common.
What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { orderId = "SO-1042", lines = { { rush = false }, { rush = true } } }Steps
- Return
orderId: the order's id frominput.orderId. - Add
lineCount: how many lines the order has. - Add
rush:trueif any line hasrushset totrue, otherwisefalse.
Show a hint
table.any from Table helpers answers "does any line…?".
A line without rush has it as nil, so compare with true.