Scripts can be found and created in different places of Chataigne. Depending on where they are executed, different methods and callbacks are available. Here are the different script types :

Module Scripts

Condition Scripts

Consequence Script

Mapping Filter Scripts

Mapping Output Script

<aside> 💡 When creating a script, the generated file will be pre-filled with contextual methods and functions depending on where it has been created. This allows for easily starting a new script with already relevant methods and callbacks !

</aside>

Common Reference

This is the common reference for all scripts, no matter their type

Here you can find an almost exhaustive reference on Chataigne specific functions.

<aside> 💡 Scripts in Chataigne are based on a simplified version of Javascript. Most functions are available, but some might be missing. If you're missing some functions, please contact me and consider donating so I can spend more time improving Chataigne !

</aside>

<aside> 💡 This documentation only shows functions that I have added on top of JUCE's Javascript Engine. To know all the base functions that are available, you can take a look at the JavascriptEngine's source code

</aside>

Common Functions

There are few common functions that you can use, no matter the type of script.

<aside> 💡 None of the functions below are needed when making a script, they are just helper functions. If you don't need them, don't add them in your script as Chataigne will optimize your script depending on the available functions in it.

</aside>

Method Description Example
init() If present, this function will be called right after the script is loaded. function init() {
//init your values, log things and assign variables
}
update(deltaTime) If present, this function will be called regularly at rate specified by the "Update rate" script parameter. This parameter is only visible when the function is present in the script. You can also change the rate from the script by calling script.setUpdateRate*(rate).* see below for more informations.
deltaTime is in seconds, and the rate parameter is in Hz. function update(deltaTime)
{
script.log("Delta time : " + deltaTime);
}
**messageBoxCallback(**id, result) This function is called when a user has made a choice in a message box launched by this script. function messageBoxCallback(id, result) {script.log("Message box callback : "+id+" > "+result); }

Parameters and triggers

All parameters and triggers have common methods and specific methods

Common methods and properties

Method Description Example
getParent() Returns the parent of this parameter myParam.getParent();
setName(name) Sets the parameters name myParam.setName("new name");
setAttribute(attribute, value) Sets a parameter's attribute.
All parameters get :
readonly : sets the parameter as not editable
description : change the tooltip description
enabled : enable or disable this parameter
alwaysNotify : set the alwaysNotify flag (if true, this will trigger updates even if setting the same value than before).
More information for specific parameters in each parameter's section. myParam.setAttribute("readonly",true);
myParam.setAttribute("description"," new description");
myParam.setAttribute("enabled",false);
myParam.setAttribute("alwaysNotify", true);
isParameter() returns whether the target is a parameter or a trigger var isParam = myTarget.isParameter();
name This is the name identifier of the object, as you would target it in a script. script.log(myParam.name);
niceName This is the "nice name" of the object, as you see it in the Inspector. script.log(myParam.niceName);
getControlAddress ([reference]) Returns the OSC-style control address of this element. Optional reference parameter allows you to specify a root container to generate the address from. script.log( myParam.getControlAddress());
getScriptControlAddress() Returns the script control address of this element. script.log( myParam.getScriptControlAddress());
resetValue() Resets the value to its default myParam.resetValue();

Trigger

Method Description Example
trigger() Returns the value of this parameter myTrigger.trigger();

Float Parameter

Method Description Example
get() Returns the value of this parameter var value = myFloatParam.get();
set(value) Sets the value of this parameter myFloatParam.set(.5);
setAttribute(attribute, value) Specific attributes :
ui : The UI to use to show this parameter. Accepted values are : ***time, slider, stepper, label
unitSteps:*** Which step size to use for this parameter. Set to 0 for free modification
stringDecimals: How many decimals to use when converting to String myStringParam.setAttribute ("ui", "time");