-
Notifications
You must be signed in to change notification settings - Fork 15
Variables
Modules are able to expose values to the user, which they can use as part of the button text, or as input to some actions.
This section explains how to define variables and change update their values.
Your module can define the list of variables it exposes by making a call to this.setVariableDefinitions({ ...some variables here... })
. You will need to do this as part of your init()
method, but can also call it at any other time if you wish to update the list of variables exposed.
Note: Please try not to do it too often, as updating the list has a cost. If you are calling it multiple times in a short span of time, consider if it would be possible to batch the calls so it is only done once.
The boilerplate has a file variables.js
which is where your variables should be defined. It is not required to use this structure, but it keeps it more readable than having it all in one file.
All the variable definitions are passed in one javascript array, such as:
;[
{ variableId: 'variable1', name: 'My first variable' },
{ variableId: 'variable2', name: 'My second variable' },
{ variableId: 'variable3', name: 'Another variable' },
]
Note: variableId must only use letters [a-zA-Z], numbers, underscore, hyphen.
At any point in your module you can call this.setVariableValues({ ... new values ... })
. You can specify as many or few variables as you wish in this call. Only the ones you specify will be updated.
This may look like:
this.setVariableValues({
'variable1': 'new value'
'variable2': 99,
'old_variable': undefined // This unsets a value
})
Note: Please try to batch variable updates whenever possible, as updating the values has a cost. If you are calling it multiple times in a short span of time, consider if it would be possible to batch the calls so it is only done once.
Getting Started
- Home
- Module development 101
- Git crashcourse
- Upgrading a module built for Companion 2.x
- Companion module library versioning
- Releasing your module
Development
- File Structure
- manifest.json
- Logging
- Module packaging
- Actions
- Feedbacks
- Presets
- Input Field Types
- Module configuration
- Upgrade scripts
- Variables
Code quality
Advanced functionality