From 58d1b0e09de3c8c2c8c8aaf44d7da84c3c031974 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 30 Mar 2020 19:15:35 +0200 Subject: [PATCH] docs: JS{{}} docs --- .../docs/docs/advanced-property-syntax.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/docs/docs/advanced-property-syntax.md b/resources/docs/docs/advanced-property-syntax.md index 3ab40b88..2e55d9da 100644 --- a/resources/docs/docs/advanced-property-syntax.md +++ b/resources/docs/docs/advanced-property-syntax.md @@ -52,7 +52,6 @@ This syntax allows listening on an osc address to define a property. The `address` can contain `@{}` blocks - ## Javascript: `JS{{ }}` This syntax allows writing formulas in pure javascript. The code will be compiled as a function and executed in a restricted context. @@ -60,8 +59,21 @@ This syntax allows writing formulas in pure javascript. The code will be compile - if no `return` statement is found, the formula will return an empty string - javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled - `setTimeout` and `setInterval` functions are not available -- the `global` object is shared between all javascript formulas (changing its properties *does not* trigger any synchronisation even if the value is used somewhere else) -In this context, `@{} / OSC{}` are seen as variables, not as the value they hold, +#### Available variables + +- `console`: javascript console +- `locals`: object for storing/reading arbitrary values. Changing its properties *does not* trigger any synchronisation even if the value is used somewhere else. +- `globals`: same as `locals` but shared between all widgets, contains a few useful variables: + - `screen`: `{width, height}` + - `env`: client options (ie: url query options), + - `url`: server url, + - `platform`: operating system as seen by the client + +In this context, `@{} / OSC{}` are also seen as variables (named `VAR_XXX`), not as the value they hold, Parsing errors can be read in the DevTool console (F12). + +## Javascript shorthand: `#{ }` + +This is a shorthand for the `JS{{}}` syntax, the only difference being that `` is automatically prepended with a `return` statement.