Skip to content

Templates

Logodaedalus edited this page Dec 10, 2018 · 3 revisions

Summary

Templates allow writers to put dynamic text into their text.
They can:

  • Surface the story state
  • Provide random text for repeatedly visited fragments
  • Surface story config settings like character names

Available Templates

rnd: pick a random option from the provided ones

  • Code: Joe {rnd|jumped|kicked}.
  • Rendered:
    • Joe kicked.
    • Joe jumped.

ifStateCondition: display certain text if a state condition is true, fallback text if not.

  • Code: Joe {ifStateCondition|happiness gte 4|smiled|frowned}.
  • Rendered:
    • Joe smiled.
    • Joe frowned.

name: displays the name of the character. (requires name set in "properties" in character section of scene-config)

  • Code: "Hey!" {name|antagonist} yelled.
  • Rendered: "Hey!" Tracie yelled.

nickname: displays the nickname of the character. (requires nickname set in "properties" in character section of scene-config)

  • Code: "Hey, {nickname|antagonist}."
  • Rendered: "Hey, T."

charTrait: displays the value of a character trait, or a fallback.

  • Code: Zanita loved to eat {charTrait|antagonist|favFood|food, in general}.
  • Rendered:
    • Zanita loved to eat carnitas.
    • Zanita loved to eat food, in general.

ifCharTraitIs: displays text if a character trait has a certain value, or a fallback.

  • Code: Zanita {ifCharTraitIs|antagonist|boldness gt 5|hollered|whispered}.
  • Rendered:
    • Zanita hollered.
    • Zanita whispered.

Templates Nest

You can also nest templates inside each other to do additional state checks, etc. Just put parentheses around them!

Example:
{ifState|firstLectureFinished|true|({ifState|firstLectureSuccess|true|You played it and didn't lose your cool! Awesome!|You played it and lost your cool! Oh no!})|First lecture hasn't been played yet!}

  • If firstLectureFinished is true and firstLectureSuccess is true: You played it and didn't lose your cool! Awesome!
  • If firstLectureFinished is true and firstLectureSuccess is false: You played it and lost your cool! Oh no!
  • If firstLectureFinished is false: First lecture hasn't been played yet!

What Can I Template?

  • Scene config:
    • fallbackText
    • introText
    • descriptionText
    • wishlist items
  • Scene content:
    • content
    • choiceLabel

Writing Your Own

New Templates can be written by adding them as properties to the templates variable in the beginning of \js\StoryAssembler\js\Templates.js
In general these are just writing hooks to surface what's put into the characters array in the scene config file. Once you have the pattern down, it's fairly easy to add character-specific traits and surface those in the text!