How To Call It
PhaseGate is a global table: call its functions with a dot (PhaseGate.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Creates a Time/Repeat gate and returns its handle. Its clock starts at the first PhaseGate.next call.
Documented for app version 1.0.51 (not on Google Play yet)Updated:
PhaseGate is a global table: call its functions with a dot (PhaseGate.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Core flow APIs are usually the backbone of larger scenarios; keep them anchored to clear checkpoints and readable variables.
Optional: options (omit to pass nil and use the runtime default). Returns a Lua table.
Options: trueMode and falseMode = "count" (visits, the default), "ms" or "seconds"; trueLimit and falseLimit are positive whole numbers (default 1; at most 1,000,000,000 visits, 604,800,000 ms or 604,800 seconds); repeatCycle (default true) decides whether the false phase returns to the true phase, and startWithTrue (default true) picks the first phase. A new table given to next or reset is a complete configuration: omitted fields return to their defaults. An invalid handle, an unknown unit, a zero, negative, fractional or oversized limit and a non-boolean flag raise an error.
Using this API with logging, error handling, and next-step control produces much more professional results than calling it in isolation.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })local stepOk = true
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
end)
if not ok then
print("API step failed: PhaseGate.create: " .. tostring(err))
requestStop()
end-- Core flow APIs are usually the backbone of larger scenarios; keep them anchored to clear checkpoints and readable variables.
local function run_create_step()
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
end
local ok, err = pcall(run_create_step)
if not ok then
toast("Step failed")
print(err)
end-- Three working visits, then one skipped visit, repeated (Macro Handler 1.0.51 or later)
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
for visit = 1, 8 do
if PhaseGate.next(gate) then
print("work", visit)
else
print("skip", visit)
end
end
local state = PhaseGate.status(gate)
print(state.phase, state.visits, state.total, state.cycles, state.elapsedMs)
PhaseGate.reset(gate)