strand-core
v3.0.1
Published
Basic narrative engine core inspired by Twine
Downloads
10
Readme
strand
Basic narrative scripting + interpreter inspired by Twine
npm i strand-core
language
note: anywhere JS
appears here, it is embedded javascript to be evaluated in the context of the interpreter instance.
::string
: Marks the beginning of a passage with the titlestring
. Between this line and the next passage title/EOF will be the body of the passage.[[string|JS]]
: Creates an action node with the textstring
and actionJS
. Expected use for this is to create buttons, links, etc and have the renderer tell the interpreter to evaluate the action on click<<do JS>>
: EvaluatesJS
when the passage is executed<<if JS>><<elseif JS>><<endif>>
: EvaluatesJS
inside the "if". If it evaluates to a truthy value, execution will continue along that branch and the rest will be ignored. If it evaluates to a falsey value, the same is repeated for each "elseif".<<print JS>>
: EvaluatesJS
when the passage is executed, and creates a text node with the evaluated value- anything else: Creates a text node
shorthands
[[link]]
: Shorthand for[[link|this.goto("link")]]
[[link>target]]
: Shorthand for[[link|this.goto("target")]]
>
or>string
: Shorthand for a "passage break", i.e. adds a link with the textstring
and an automatically generated passage heading. Expected use for this is breaking up long passages into multiple purely linear interactions without needing to mark up each one individually>a|b|c
: Same as above, but creates multiple links split by|
that all link to the same automatically generated passage<<set var=val>>
: Shorthand for<<do this.var=val>>
<<else>>
: Shorthand for<<elseif true>>
example
::start
some text with a [[shorthand link]] and a longform [[action|this.goto("other passage")]]
::shorthand link
<<set linkClicked=true>>this passage appears when you click the link
[[back|this.back()]]
::other passage
<<if this.linkClicked>>
this text shows up if you visited the shorthand link passage before getting here
<<else>>
this text shows up if you didn't
<<endif>>