Caffeine

Session

Reference Game Last updated: Lua 5 · Dryad 5

A key-value store that survives scene changes for as long as the game runs (score, settings, choices). Values are numbers, booleans or text. It is not saved to disk.

All namespaces

Namespace: caffeine.session · Dryad prefix: caffeine_session_

set#

Lua: caffeine.session.set · Dryad: caffeine_session_set

text
set(key, value)

Stores a value.

ParametersTypeDescription
keystringName of the value.
valuenumber | boolean | string | nilThe value to keep; nil removes the key.

Returns: none

Example

lua
caffeine.session.set("coins", 12)

get#

Lua: caffeine.session.get · Dryad: caffeine_session_get

text
get(key) -> any

Reads a value.

ParametersTypeDescription
keystringName of the value.

Returns: number | boolean | string | nil. The stored value, or nil when the key does not exist.

Example

lua
local coins = caffeine.session.get("coins") or 0

has#

Lua: caffeine.session.has · Dryad: caffeine_session_has

text
has(key) -> boolean

Tells whether a key exists.

ParametersTypeDescription
keystringName of the value.

Returns: boolean. true when the key exists.

Example

lua
if caffeine.session.has("checkpoint") then end

remove#

Lua: caffeine.session.remove · Dryad: caffeine_session_remove

text
remove(key) -> boolean

Deletes a key.

ParametersTypeDescription
keystringName of the value.

Returns: boolean. true when the key existed.

Example

lua
caffeine.session.remove("checkpoint")

clear#

Lua: caffeine.session.clear · Dryad: caffeine_session_clear

text
clear()

Deletes every key.

Returns: none

Example

lua
caffeine.session.clear() -- new game