Session
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.
Namespace: caffeine.session · Dryad prefix: caffeine_session_
set#
Lua: caffeine.session.set · Dryad: caffeine_session_set
set(key, value)
Stores a value.
| Parameters | Type | Description |
|---|---|---|
key | string | Name of the value. |
value | number | boolean | string | nil | The value to keep; nil removes the key. |
Returns: none
Example
caffeine.session.set("coins", 12)
get#
Lua: caffeine.session.get · Dryad: caffeine_session_get
get(key) -> any
Reads a value.
| Parameters | Type | Description |
|---|---|---|
key | string | Name of the value. |
Returns: number | boolean | string | nil. The stored value, or nil when the key does not exist.
Example
local coins = caffeine.session.get("coins") or 0
has#
Lua: caffeine.session.has · Dryad: caffeine_session_has
has(key) -> boolean
Tells whether a key exists.
| Parameters | Type | Description |
|---|---|---|
key | string | Name of the value. |
Returns: boolean. true when the key exists.
Example
if caffeine.session.has("checkpoint") then end
remove#
Lua: caffeine.session.remove · Dryad: caffeine_session_remove
remove(key) -> boolean
Deletes a key.
| Parameters | Type | Description |
|---|---|---|
key | string | Name of the value. |
Returns: boolean. true when the key existed.
Example
caffeine.session.remove("checkpoint")
clear#
Lua: caffeine.session.clear · Dryad: caffeine_session_clear
clear()
Deletes every key.
Returns: none
Example
caffeine.session.clear() -- new game