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.
Reads the gate without changing it: phase (nil before the first visit), visits, total, cycles, mode, limit and elapsedMs. It never changes the phase, even when the time is up.
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.
Required: gate. 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 })
PhaseGate.next(gate)
local result = PhaseGate.status(gate)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 })
PhaseGate.next(gate)
local result = PhaseGate.status(gate)local stepOk = true
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
PhaseGate.next(gate)
local result = PhaseGate.status(gate)
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
PhaseGate.next(gate)
local result = PhaseGate.status(gate)
end)
if not ok then
print("API step failed: PhaseGate.status: " .. 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_status_step()
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
PhaseGate.next(gate)
local result = PhaseGate.status(gate)
end
local ok, err = pcall(run_status_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)