Operators and decisions
LESSON 04
Use arithmetic to drive a puzzle, then choose exactly one response.
local Script = {}function Script.run(context)
local ticks = 17
local turns = ticks // 6
local remainder = ticks % 6
local response
if turns < 1 then
response = "Wind the clock."
elseif remainder == 0 and turns >= 2 then
response = "The teeth line up."
else
response = "Advance " .. (6 - remainder) .. " tick(s)."
end
return response
endreturn ScriptThe result is “Advance 1 tick(s).” Change ticks to 12 for the aligned branch. Integer floor division //
counts completed turns. The % operator returns the remainder. The / operator returns a
floating-point quotient. Use +, -, *, and ^ for addition, subtraction, multiplication and powers.
Use = to assign, == or ~= to test equality, and <, <=, > or >= to compare. Parentheses make
precedence explicit. The .. operator joins strings. For branching, and and or return operands, and
not returns a Boolean. Distinguish a missing setting from false with an explicit value == nil check.
