From 4a4ccdb60312065f887c80618f7d0e612d924609 Mon Sep 17 00:00:00 2001 From: Andrew Cantino Date: Wed, 9 Sep 2020 16:03:05 -0700 Subject: [PATCH] Document authorsNote --- README.md | 7 ++++++- examples/authorsNote.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 examples/authorsNote.js diff --git a/README.md b/README.md index d1dd538..ea92f88 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,12 @@ You have access to (but can't modify) the `history` object which is a list of th ### Memory You have access to (but can't modify) the `memory` object which is the current user defined memory. You can modify the memory the game uses by settings the `state.memory.context` value. This will replace the user defined memory. -You can also set `state.memory.frontMemory` which will include whatever is there in front of even the last action when it's fed into the model, but still not display it to the user. +You can also set `state.memory.frontMemory`, which will include whatever is there in front of even the last action when it's fed into the model, but still not display it to the user. + +### Author's Note +You can set `state.memory.authorsNote` to provide a piece of text that will always be injected three lines back in the game history. This will not be shown to the user, but the AI will see it. + +As an example, if you set `state.memory.authorsNote` to `the following paragraphs are scary.`, the AI will see `[Author's note: the following paragraphs are scary.]` three lines back, causing it to be more likely to generate scary text. Another example could be `a dragon will show up soon` or `the player will soon receive a quest`. ### Quests You can modify the quests property to change the quests of the adventure mid game. diff --git a/examples/authorsNote.js b/examples/authorsNote.js new file mode 100644 index 0000000..1aa41e5 --- /dev/null +++ b/examples/authorsNote.js @@ -0,0 +1,40 @@ +const themes = [ + { + text: 'ghost story', + matcher: /ghost|halloween|spooky/i, + }, + { + text: 'trick-or-treat', + matcher: /trick.or.treat|halloween|spooky/i, + }, + { + text: 'spooky', + matcher: /halloween|spooky/i, + }, +] + +const modifier = (text) => { + if (!state.setup) { + state.theme = Math.floor(Math.random() * themes.length) + state.setup = true + state.matched = false + } + + const theme = themes[state.theme] + + if (!state.matched && text.match(theme.matcher)) { + state.matched = true + } + + if (state.matched) { + state.memory = {} + } else { + const halloween = ` It involves Halloween and has a ${theme.text} theme.` + state.memory = { authorsNote: `the rest of this story is silly & playful.${halloween}` } + } + + return {text} +} + +// Don't modify this part +modifier(text)