Skip to main content
The CloudScript runtime environment supports most of the modern ECMAScript 6 features. While a majority of these features are syntactical tricks, you can use them to improve and clean your CloudScript code. A complete overview of ES6 features is available in this Cheat Sheet. This tutorial shows several tricks you may use in your CloudScript.
Some of the features require strict mode. Enable this mode by placing the following code as the very first line of your CloudScript file: use strict;

String interpolation

When composing messages for your players, you may want to use multi-line interpolated strings. Use the back-tick symbol to create an interpolated string. You may then insert data right into the string using ${ variable } syntax. This allows you to avoid string concatenation and improves code readability.
Back-tick strings are verbatim and may be multi-line. This means you have to keep an eye on all indention, as any extra space/tab will be captured into the string.

New methods and arrow functions

ES6 brings new syntax for defining functions using the arrow operator =>. The snippet displayed below shows approximate translations for certain operator usages.
This operator, combined with the new Array.findIndex method, allows searching by predicate with the following well-looking, succinct code.

Object assignment

The Object.assign method allows you to easily extend any object with a new set of properties and methods. Having a large variety of usages, this method is particularly useful for extending a handlers object and creating groups of handlers.
This not only allows you to quickly enable and disable handler groups, but it also gives you a point to process your handlers and wrap them with useful code, such as exception handling. The following code extends the previous snippet with automatic exception logging. As an example, we log the problem (which is not always useful), but you can extend the behavior to your taste.

Getters

One may use “Getters” to encapsulate common API calls into a more syntactically pleasing look and feel. Consider the following Title Data state. The following snippet shows how to retrieve Foo and Bar data from TitleData and then use them in a very straightforward way.
Last modified on August 10, 2026