When you need to write more complex conditions or expressions than is possible with just the COGS UI tools, you need to drop down to using “custom code”.
Anywhere where it’s possible to use custom code, when you switch away from the UI based template, the custom code input will be populated with the expression that was being used under the hood when using the UI tools. This is a good way to get started in understanding how to write expressions:
becomes
Version | Expression | |
---|---|---|
4.0 → | pre_show.in_progress |
Show is in “pre-show” |
4.11 → | scene.variables.score.value * 10 |
The player’s score x 10 |
4.11 → | !this.value |
Invert on/off value |
In COGS land we refer to all these “custom code” snippets as expressions, but there are two main places they can be used which have slightly different uses.
When writing expressions in the WHEN of a behaviour, or the condition section of an IF/THEN/OTHERWISE or a LOOP then these are conditions. The aim is to write an expression which will return true or false. In the case of a WHEN condition, the behaviour will run when the condition returns true but was previously false.
When writing expressions to display as values (such as in a scene dashboard widget), then the aim is to write an expression that returns a value of the correct type. e.g. for a “Text widget” on a dashboard, the expression should return a string type.
COGS expressions are written in the JEXL expression language, which is based on Javascript syntax.
This supports many of the standard operators common to many programming languages and more, e.g.