Macros

Macros are built-in functions that perform some common tasks. Below is a list of some common macros that you can use at any stage in your CSML flows.

OneOf

Return one the elements of the array passed in the first argument at random.

Useful for randomisation of dialogue parts!

say OneOf(["I like you", "You're awesome"])

Shuffle

Given an array, return it with its elements in a random order.

Especially useful in questions to randomize the available options!

do btn1 = Button("Blue")
do btn2 = Button("Red")
do btns = Shuffle([btn1, btn2])
say Question(
title = "Select a pill",
buttons = btns
)

Find

Return whether a string is contained in another string.

say Find("needle", in="haystack") // false
say Find("yes", in="well yes, I like cheese") // true

Length

Return the length of a given string or array

say Length("My horse is amazing") // 19
say Length([1, 2, 3]) // 3

Random

Return a random floating point number in the range 0-1 (0 included, 1 excluded).

say Random() // 0.03196249773128712
say Random() // 0.6416423921015862

Floor

Return the largest integer less than or equal to the given number.

say Floor(1.23456) // 1

This is useful to generate a random integer in a given range:

say Floor(Random() * 5) // a random integer between 0-4 (included)
say Floor(Random() * 8) + 12 // a random integer between 12 - 19 (included)