Store and refresh character memories - part 2
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()func forget_short_term() -> void:
await SetVariable({"name":"stm_" + ActivePlayer(), "value":[]})
await refresh()func run(_context: Dictionary = {}) -> Variant:
await remember("window", "Broken window")
return trueThe 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.
