Narrat Docs
Search…
If function

if function

The $if command is the main method of doing conditions in narrat. It can be used to branch inside a script, or to make choice options conditionally available.
Syntax: $if [condition]:
If conditions have access to the following:
  • DATA: The object containing the game variables created by functions like set and add
  • SKILLCHECKS: The object containing the state of skill checks that have been passed
Note: The $if command is special and uses eval behind the scene to evaluate your condition as a piece of JavaScript that gets given access to specific variables

Example

1
set_example:
2
choice:
3
talk cat idle "Do you like surprises?"
4
"Yes":
5
set DATA.like_surprises true
6
"No!":
7
set DATA.like_surprises false
8
$if this.DATA.like_surprises:
9
talk cat idle "Since you like surprises, here's a surprise message"
Copied!
Result of the above code
Copy link