Skip to content
ForgeCastDocs

Counters, queues, countdowns, leaderboards

Ready-made pieces that save themselves, draw their own Dashboard controls and fill your overlays.

Functions

Counter:get()

The number now.

Returns number

Counter:add(n)

Add to it (1 by default; negative takes away).

  • n: number, optional

Returns number

Counter:set(v)

Set it to a number.

  • v: number

Returns number

Counter:reset()

Back to where it started.

Returns number

Counter:on_change(fn)

Run a function whenever it changes.

  • fn: fun(value: number)

counter.create(name, opts)

A number with buttons: a death counter, wins, hydration… {{plugin.<id>.deaths}} shows it.

  • name: string. a letter, then letters, digits or _
  • opts: CounterOptions, optional

Returns Counter

Queue:join(user)

Add a viewer (a chat author, or a name): their place, or nil and "already" (with their place) or "full".

  • user: ChatAuthor|string

Returns integer? place; string? why

Queue:leave(user)

Take a viewer off the queue.

  • user: ChatAuthor|string

Returns boolean

Queue:next()

Take the first one off the queue.

Returns QueueEntry?

Queue:peek(n)

The first n waiting (1 by default), without taking them off.

  • n: integer, optional

Returns QueueEntry[]

Queue:list()

Everyone waiting, in order.

Returns QueueEntry[]

Queue:size()

How many are waiting.

Returns integer

Queue:position(user)

A viewer's place, or nil.

  • user: ChatAuthor|string

Returns integer?

Queue:remove(i)

Take the one at place i off the queue.

  • i: integer

Returns QueueEntry?

Queue:clear()

Empty the queue.

Queue:on_change(fn)

Run a function whenever the queue changes.

  • fn: fun(items: QueueEntry[])

queue.create(name, opts)

A queue of viewers (to play with you, to be next…). Overlays get <name>_next, <name>_size and <name>_list (the first five).

  • name: string. up to 20 characters
  • opts: QueueOptions, optional

Returns Queue

Countdown:start(seconds)

Start (or carry on).

  • seconds: number, optional. a new length

Countdown:pause()

Pause it, keeping the time left.

Countdown:resume()

Carry on after a pause.

Countdown:reset(seconds)

Stop it and put the full time back (or a new length).

  • seconds: number, optional

Countdown:add(seconds)

Add (or, negative, take away) time.

  • seconds: number

Countdown:left()

Seconds left.

Returns integer seconds_left

Countdown:running()

Whether it is counting down now.

Returns boolean

Countdown:on_done(fn)

Run a function when it reaches zero.

  • fn: fun()

Countdown:on_tick(fn)

Run a function every second while it runs.

  • fn: fun(seconds_left: integer)

countdown.create(name, seconds, opts)

A countdown with Start, Pause, +1 min and Reset. Overlays get <name> ("4:59"), <name>_seconds and <name>_running.

Name

Type

Returns Countdown

Leaderboard:add(user, n)

Add points to a viewer (1 by default): their new score.

  • user: ChatAuthor|string
  • n: number, optional

Returns number score

Leaderboard:set(user, n)

Set a viewer's score.

  • user: ChatAuthor|string
  • n: number

Returns number

Leaderboard:get(user)

A viewer's score (0 when they have none).

  • user: ChatAuthor|string

Returns number

Leaderboard:rank(user)

A viewer's place, or nil.

  • user: ChatAuthor|string

Returns integer?

Leaderboard:top(n)

The best n (its size by default), with their rank.

  • n: integer, optional

Returns Score[]

Leaderboard:reset()

Wipe every score.

Leaderboard:on_change(fn)

Run a function whenever a score changes.

  • fn: fun(top: Score[])

leaderboard.create(name, opts)

Scores by viewer. Overlays get the top five as <name>_1_name, <name>_1_score … <name>_5_score.

Returns Leaderboard

Types

Open a type to see its fields; type names above link here.

On this page