OPX//77
opx_infinityprogress

Client

Last updated on

The progress contract on the client — put a bar up, take it down, read whether one is up.

local progress = OPX.Api.Get('progress')

From client code inside opx_infinity. Each function answers a Result. None yields.

Start

Puts a bar up. Answers whether the bar is up, not whether the action happened: the outcome arrives on opx:on:progress:done.

progress.Start(owner, spec)

Parameters

  • owner: string
    • Your module name; needed for Stop.
  • spec: table
    • label: string
      • Required. Cut to 64 bytes. Your own text.
    • durationMs: number
      • Required. Between MIN_MS and MAX_MS.
    • animation?: table
      • { name, variant? }. Played through animations.Play (looped, not cancellable) and stopped with the bar. Ignored if animations is not running or refuses it.
    • cancelable?: boolean
      • Default false. Lets the player cancel the bar with CANCEL_KEY.

Returns

  • Result — { owner, durationMs }; errors invalid_caller, invalid_spec, progress_busy, invalid_duration, invalid_label
Example
local r = progress.Start('mymodule', { label = 'Eating', durationMs = 4000 })
AddEventHandler('opx:on:progress:done', function(done)
  if done.owner == 'mymodule' and done.finished then --[[ apply the effect ]] end
end)

Stop

Takes the owner's bar down early.

progress.Stop(owner, ending)

Parameters

  • owner: string
  • ending?: string
    • 'cancelled' reports cancelled; anything else reports stopped.

Returns

  • Result — true; errors progress_not_active, not_owner

State

Whether a bar is up, and whose.

progress.State()

Returns

  • Result
    • { open = false, cancelledAtMs? }
    • or { open = true, owner, label, remainingMs, cancelable, cancelKey?, cancelledAtMs? }
      • cancelable: boolean — the player may cancel it with the key
      • cancelKey?: string — the key the cancel is bound to now, when cancelable
      • cancelledAtMs?: integer — OPX.Now() of the last cancel by key. For a module sharing the key: a press within a few hundred ms of it was the bar's.
Example — X is not mine while a cancelable bar is up
local bar = OPX.Api.Get('progress').State().value
if bar.open and bar.cancelable then return end
if bar.cancelledAtMs and OPX.Now() - bar.cancelledAtMs < 300 then return end

On this page