Math, randomness and vectors
LESSON 08
Keep a gauge within its bounds and give a misplaced gear a measurable distance from its socket.
local Script = {}function Script.run(context)
local charge = math.max(0, math.min(100, 87 + 22))
local angle = math.rad(90)
local direction = math.floor(math.sin(angle) + 0.5)
local choices = { "one chime", "two chimes", "silence" }
local clue = choices[math.random(1, #choices)]
local offset = Vector3(3, 0, 4)
return { charge = charge, north = direction,
distance = offset:length(), clue = clue }
endreturn ScriptExpect charge 100, north 1, distance 5 and one of the three strings. math.floor rounds down and
math.ceil rounds up. math.abs gives magnitude. math.sin and math.cos take radians.
math.random(lo, hi) includes both integers. Use a stored puzzle solution if a random choice must
survive a reload.
The bridge also supplies Clamp, Lerp, Distance, RandomInt and Choose. Use a consistent random
generator when reproducing a bug. math.randomseed controls Lua randomness. PCA's Randomize
controls its engine-side generator.
