Skip to content
ForgeCastDocs

Storage, timers and data

Keep data, run things later, write to the console, read and write JSON.

Functions

storage.get(key, default)

Read something you saved (nil, or default, when there is nothing).

  • key: string
  • default: any, optional

Returns any

storage.set(key, value)

Save a value (a string, number, boolean or table of those; nil removes it). Up to 1 MB per plugin.

  • key: string
  • value: any

storage.delete(key)

Forget one saved value.

  • key: string

Returns boolean existed

storage.keys()

The names of everything saved, in order.

Returns string[]

storage.clear()

Forget everything saved.

timer.after(ms, fn)

Call fn once after ms milliseconds. Returns an id for timer.cancel.

  • ms: number
  • fn: fun()

Returns integer id

timer.every(ms, fn)

Call fn every ms milliseconds (50 at the least).

  • ms: number
  • fn: fun()

Returns integer id

timer.cancel(id)

Stop a timer made with timer.every or timer.after.

  • id: integer

Returns boolean found

log.debug(...)

Write to the console at debug level (hidden until you show debug lines).

  • ...: any

log.info(...)

Write an information line to the console.

  • ...: any

log.warn(...)

Write a warning to the console.

  • ...: any

log.error(...)

Write an error to the console. It doesn't stop the plugin.

  • ...: any

print(...)

Same as log.info: shows in the plugin's console.

  • ...: any

unpack(list, i, j)

The same as table.unpack: the items of a list as separate values (Lua 5.1's name, kept so code from tutorials works).

Name

Type

Returns any

json.encode(value, pretty)

Turn a value into JSON text. Tables with keys 1..n become lists, others objects.

  • value: any
  • pretty: boolean, optional

Returns string

json.decode(text)

Read JSON text. Returns nil and a message when it isn't valid.

  • text: string

Returns any value; string? err

time.now()

Milliseconds since 1970.

Returns integer

require(name)

Load another .lua file from the plugin's folder: require("helpers") or require("lib.util").

  • name: string

Returns any

On this page