CSML updates
CSML updates
www.csml.dev

CSML v1.8.0 is out!

 

New

  

We have just released CSML v1.8.0! This new version is PACKED with super useful features that we are extremely happy to finally share with you today. Let's do a quick roundup of all the new stuff!

while loops

This one is certainly one of the most requested features of all times, and for good reasons. You can now use standard while loops to iterate over any type of data (and not just arrays as was previously possible using foreach):

do i = 0
while (i < 3) {
  say "i = {{i}}"
  do i = i + 1
}

string.replace() helpers

Another very useful feature that makes it trivial to replace part of a string with something else, which was previously quite hard to achieve in pure CSML, the .replace() family of string methods (which include replace, replace_all and replace_regex) are also part of this release.

// .replace() will only replace the first occurrence
// of the first term with the second term
say "My dog Bark is nice, but my other dog Groot is mean".replace("dog", "cat") 
// => "My cat Bark is nice, but my other dog Groot is mean"

// .replace_all() will replace all occurrences
say "My dog Bark is nice, but my other dog Groot is mean".replace_all("dog", "cat") 
// => "My cat Bark is nice, but my other cat Groot is mean"

// .replace_regex() uses regular expressions 
say "My dog Bark is nice, but my other dog Groot is mean".replace_regex("[a-gA-G]", "%")
// => "My %o% %%rk is ni%%, %ut my oth%r %o% %root is m%%n"

Compound assignment operators

Yes, that's the name of the operator that lets you perform an operation at the same time that it assigns the result. For example:

do i = 1
do i += 5
say "i = {{i}}" // i = 6

Concatenate strings with the + sign

One of the feedbacks we sometimes had was that it is not always easy to concatenate strings together. It has always been possible using string interpolation, but the syntax is not too easy:

do firstname = "John"
do food = "cheese"
say "{{firstname}} likes {{food}}"

You can now use the + sign to do the same thing:

say firstname + " likes " + food

Add and subtract time from a Time() value

Obviously, one of the most common needs when manipulating times is to add or subtract time, for example when comparing two dates. The .add() and .sub() methods do exactly that:

do t1 = Time() // now
do t2 = t1.add(3600) // in 1 hour
do t3 = t1.sub(86400) // 1 day ago

Get local flow context in conversation

The _metadata global variable now has a new read-only inner property _context, which contains information about the user's current whereabouts in the flow. This object contains 2 new properties current_flow and current_step, and 2 optional properties previous_flow and previous_step that are only set when the user comes from a different step or flow (i.e after a goto).

start:
  say "{{_metadata._context}}" // will only print `current_*` properties
  goto step1

step1:
  say "{{_metadata._context}}" // will print all 4 properties
  goto end

Check if a variable has been set with Exists("var")

Last one for today: we have introduced a new built-in function to check if a variable currently exists in the bot's memory. This is useful for checking not only if the value is a null/false/empty value, but if it exists at all!

remember myVar = "somevalue"
do Exists("myVar") // true
remember myVar = null
do Exists("myVar") // true
forget myVar
do Exists("myVar") // false

The team has been busy making a lot of other improvements and features that may also interest you, so make sure to check the release notes, and please visit our Slack if you have any questions!