Object MethodCore FlowComing soonv1.0.51

PhaseGate.create(options?)

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:

Detailed Explanation

This section explains when to use the API, how to call it, and which structures it works best with in production flow.

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.

When To Use It

Core flow APIs are usually the backbone of larger scenarios; keep them anchored to clear checkpoints and readable variables.

Parameters and Return

Optional: options (omit to pass nil and use the runtime default). Returns a Lua table.

Options and Limits

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.

Best Combined With

Using this API with logging, error handling, and next-step control produces much more professional results than calling it in isolation.

Example Usage

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 })

Copyable Progressive Examples

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.

Foundation

Shows the shortest direct way to call the API.

Foundation
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local gate = PhaseGate.create({ trueMode = "count", trueLimit = 3, falseMode = "count", falseLimit = 1 })
if stepOk then
  wait(200)
end

Practical Flow

A practical pattern for real macros with pcall, logging, and guards.

Practical Flow
local 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

Detailed

This level packages the API into a reusable helper with error reporting.

Detailed
-- 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

Combined

Combines the API with related structures to form a more realistic workflow.

Combined
-- 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)