Built-in Functions

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"])

Or

If the first element exists return it, otherwise return the second argument as a default value

say Or(var, "default value")

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.

Length

Return the length of a given string or array

Random

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

Floor

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

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

UUID

Generate a random UUID (v1 or v4, defaults to v4)

Time

The Time() helpers lets your manipulate timestamps and dates easily.

CSML's Time function is based on Rust's Chrono library. All the formatting options are listed here: https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html

Exists

Check if a variable has been saved in the chatbot's memory before for the current user.

Last updated

Was this helpful?