Types

Comments

###
Large
  Comment
Block
###

# Inline comment

foo = "bar"  # end of line comment

In Storyscript, comments are denoted by the # character to the end of a line, or from ### to the end of the line of the next appearance of ###.

Boolean

Truth values can be represented with the boolean type that has two possible values (true and false):

happy = true
sad = false

Numbers

Numbers in Storyscript can be whole numbers (ints) that can be positive, negative or zero:

i  = 1
i2 = -2
i3 = 0

Integers are unlimited in size and have no minimum or maximum value.

Additionally, Storyscript can represent numbers with decimals as floating-point numbers (float):

f1 = 1.2
f2 = -3.14

The engine uses IEEE-754 double precision floating point arithmetic.

Strings

data = "foobar"

long_string = "Hi Friend,
This is a lo\
ng string."
# Hi Friend, This is a long string.

more_data = """
    The quick brown fox
    jumps over the lazy dog.
"""
# The quick brown fox\njumps over the lazy dog.

Like many traditional programming languages, Storyscript supports strings as delimited by the " quote characters.

Multi-line strings are allowed in Storyscript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored.

Block strings, delimited by """, can be used to hold formatted or indentation-sensitive text (or, if you just don’t feel like escaping quotes and apostrophes). The indentation level that begins the block is maintained throughout, so you can keep it all aligned with the body of your code.

String templates

Storyscript also supports string interpolation using { expression }.

where = "Earth"
data_formatted = "Hello, {where}"
# Hello, Earth

Inside string templates it is allowed to use single quotes for map access:

tr = {"greeting": "Hello", "plant": "Sun"}
reply = "{tr['greeting']}, {tr['plant']}"
# Hello, Sun

In most cases it is more readable to use map destructuring assignments instead:

tr = {"greeting": "Hello", "plant": "Mars"}
{ greeting, plant } = tr
reply = "{greeting}, {planet}"
# Hello, Mars

String indexing

A string index is zero-based. A string index may be negative and will then start from the end. The absolute value of an index may not be equal or greater than the length of the string.

s = "abcd"
s[0]  # a
s[3]  # d
s[-1] # d
s[-3] # a
s[4]  # ERROR
s[-4] # ERROR

Lists

Storyscript supports Lists as a generic container type:

list_inline = ["string", 1, 2]
list_multiline = [
  1,
  2,
  3
]

In a list the same value may occur more than once. A list index is zero-based. A list index may be negative and will then start from the end. The absolute value of an index may not be equal or greater than the length of the list.

list = [1, 2, 3, 4]
l[0]  # 1
l[3]  # 4
l[-1] # 4
l[-3] # 1
l[4]  # ERROR
l[-4] # ERROR

Maps

Storyscript supports Maps as a generic container type:

map_inline = {"foo": "bar", "apples": "oranges"}
map_multiline = {
  "foo": "bar",
  "apples": "oranges"
}
object_int = {1: 11, 2: 22}

In a map the same value may occur more than once, but the same key can only occur once.

Maps can be destructured into its part with the destructuring assignments:

map = {"foo": "bar", "apples": "oranges"}
{ foo } = map
# foo = "bar"

A destructuring assignment must contain one or more object keys. These keys must exist in the map and will be new variables names. Their value is the value of the respective key in the map (map[key]).

map = {"foo": "bar", "apples": "oranges"}
{ foo, apples } = map
# foo = "bar", apples = "oranges"

Time durations

Time durations can be expressed natively.

timeout  = 30s
duration = 5d10m

Supported time units are w (weeks),d(days),h(hours), m (minutes), s (seconds) and ms (milliseconds).

Time units must be used in this order and can not be repeated.

Regular Expressions

pattern = /^foo/i

Regular expressions are supported without any special characters of escaping necessary.

Any

Some services may return a response of type any. The Storyscript compiler will warn you about it:

any_var = json parse content: "[1]"
b = any_var + 2 # E0103: `+` between `any` and `int` is not supported.

And require a manual conversion:

any_var = json parse content: "[1]"
b = (any_var to List[int])[0] + 1

Info

Learn the methods you can call with regular expression in the Storyscript Hub

Edit this page

What story will you write?

BUILT WITH IN AMSTERDAM

2019. Asyncy, Inc.