Skip to main content
All CollectionsAIPrompts
Prompt Functions (Custom Instruction Grammar)
Prompt Functions (Custom Instruction Grammar)

Prompt functions that you can use when editing your prompts.

Updated over 8 months ago

Inside the prompt instructions, you can call functions that Novelcrafter provides you with. In this article, we will include examples of the functions where present in prompts to help you understand how to use it.

Use the following syntax to call a function:

{some.function_name(argument1, argument2, ...)}

  • Arguments that take a text (string) have to be surrounded by quotes, like this: "some text".

  • Arguments that take a number (integer) have to be written as is, like this: 123.

Note: Not all functions are available for each prompt. For example, you can’t use context.wordsBefore in a chat prompt.

Logic Gates / Branching

Like in programming, you can use logic gates, or branching, to create more complex prompts. The following logic gates are available:

  • {#if(condition)} - If the condition is true, the following text will be included in the prompt.

  • {#elseif(condition)} - If the previous if condition was false, and this condition is true, the following text will be included in the prompt.

  • {#else} - If the previous if condition was false, the following text will be included in the prompt.

  • {#endif} - Ends the previous if condition.

These conditions do not allow any comparison checks. They always pass if the given content is "truthful", which can be non-empty strings, or a numeric value other than zero.

Example: In the system prompt for scene beat completion, the {#if(condition)} is used to determine whether to pull up words before from the previous scene. The condition used here is if the POV character is the same for both scenes, then 650 words from the scene before will be used for continuity.

If the POV characters are not the same, then no text will be included.

Series

series.title

Returns the title of the associated series (if any).

series.description

Returns the description of the associated series (if any).

Example: In the general purpose system prompt for workshop chat, we can see that the series title and description are pulled up as context for the AI, informing it automatically of this information if the book is part of a larger series (from the if condition).

Novel

novel.tense

Returns the tense of the current novel. Either “past” or “present”, based on the novel's metadata.

novel.language

Returns the language of the current novel (e.g. "British English", 'French", "German", ...).

novel.pov

Returns the point of view of the current novel (as an XML string).

novel.hasSeries

Returns true if the novel is associated with a series, otherwise nothing (see here).

novel.outline

Returns the full outline of the current novel (in markdown format). Includes all scenes, even those marked as “excluded from AI”.

novel.fullText

Returns the full text of the current novel (in plaintext format). Includes all scenes, even those marked as “excluded from AI”.

Examples

You can see many of these in the scene beat completion and workshop chat prompts.

Scene Beat Completion:

Workshop Chat:

Snippets

snippets.get(title: string)

Returns the text of the snippet with the title.

Remember. "string" is just a coding term for text surrounded by quotes. So if we have a snippet called Story Summary, then we would use the following to pull it up:

snippets.get("Story Summary")

You can see it in action in the image below, from a custom prompt, where I have included a summary of the previous novel as a snippet, to be read alongside the context of the storySoFar.

Current Scene

args.scene

Returns the exact ID of the current scene, if there is one in the context.

scene.title

Returns the title of the current scene (full chapter title and scene number).

scene.summary

Returns the summary of the current scene.

scene.content

Returns the content of the current scene (in plaintext format).

scene.pov

Returns the point of view of the scene novel. Falls back to the default novel POV, if set. (see here for use case)

Example. If you select a scene context in the chat, then the prompt below pulls up the scene's title and content.

Context Data

context.storySoFar

The story contents so far (based on scene summaries). This will include all the scene summaries up to the scene before the current one (e.g. scene 1-12, when you're working on scene 13).

Example: system scene beat completion prompt

context.chapterSoFar

The story contents inside the current chapter so far (based on scene summaries). Similar to context.storySoFar.

context.sceneSoFar

The story contents until the point where the prompt gets executed (in scene beats).

context.wordsBefore(words: number)

Last N number of words of the current scene contents before the selection.

Unlike strings, numbers don't need quotation marks around them

Example: rephrase prompt

context.previousScene.lastWords(words: number)

Last N number of words of the contents of the scene prior to the current one.

Example: scene beat completion

Codex

All codex entries return the name, potential aliases/nicknames and the description of the entry.

codex.get(title: string)

Returns the description of the codex entry with the title (in plain text).

context.codex(format: string)

Returns the full list of detected codex entries in the current context (in the desired format: xml or raw for plain text).

context.codex.characters(format: string)

Returns the full list of detected characters in the current context (in the desired format: xml or raw for plain text).

context.codex.locations(format: string)

Returns the full list of detected locations in the current context (in the desired format: xml or raw for plain text).

context.codex.objects(format: string)

Returns the full list of detected objects in the current context (in the desired format: xml or raw for plain text).

context.codex.lore(format: string)

Returns the full list of detected lore in the current context (in the desired format: xml or raw for plain text).

context.codex.other(format: string)

Returns the full list of detected other codex entries in the current context (in the desired format: xml or raw for plain text).

context.codex.get(title: string)

Returns the description of the codex entry with the title (in plain text). This also includes all the codex additions up to the point where the prompt gets executed inside the scene.

Utilities

string.compress(text: string)

Compresses the string by removing punctuation and white-space (Rarely used).

context.selection

The selected text becomes part of the prompt. Used in the text replacement prompts.

Did this answer your question?