When you need to write more complex conditions or expressions than is possible with just the COGS UI tools, you can use “Computed Conditions” or “Computed Values”.
<aside>
As of COGS 5.7, Computed Values are written in ECMAScript 2023 (a.k.a. JavaScript).
</aside>
<aside>
COGS 5.6 and below uses JEXL, a JavaScript-like expression language. For JEXL documentation click here.
</aside>
<aside>
If you’re migrating an existing project from COGS 5.6 or below see Migrating from JEXL.
</aside>
Anywhere it’s possible to use Computed Values or Computed Conditions, when you switch away from the UI template, the code input box will be populated with the code that is being used under the hood when using the UI tools. This is a good way to get started in understanding how to write Computed Values and Computed Conditions.
For example:
becomes
Version | Expression | |
---|---|---|
5.7 → | pre_show.in_progress |
Pre-show phase is in progress |
5.7 → | scene.variables.score.value * 10 |
The player’s score multiplied by 10 |
5.7 → | !this.value |
Invert on/off value |
There are two main places Computed Conditions and Computed Values can be used and they have slightly different uses: