Skip to reading
Eight Adventure Interface Workshops

Store and refresh character memories - part 2

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func remember(topic: String, caption: String, long_term: bool = false) -> void:
    var kind: String = "ltm" if long_term else "stm"
    var key: String = kind + "_" + ActivePlayer()
    var values: Dictionary = Runtime.get("variables")
    var entries: Array = values.get(key, []).duplicate(true)
    for entry: Dictionary in entries:
        if str(entry.get("id", "")) == topic:
            return
    if not long_term and entries.size() >= 10:
        entries.pop_front()
    entries.append({"id":topic, "text":caption})
    await SetVariable({"name":key, "value":entries})
    await refresh()
Code example
func forget_short_term() -> void:
    await SetVariable({"name":"stm_" + ActivePlayer(), "value":[]})
    await refresh()
Code example
func run(_context: Dictionary = {}) -> Variant:
    await remember("window", "Broken window")
    return true

The default run method remembers the broken window as a convenient first test. Calling remember with long_term true writes to the active character’s long-term store instead.

Duplicate topic IDs are ignored. The short-term store’s ten-entry policy drops the oldest entry; change that policy if your game needs a visible “which memory should be replaced?” choice.

Page 102 of 119Permalink
Go to page