Global Variables
Global variables provide a way for scripts to share data and communicate with each other. Variables are stored on the appliance and persist across script executions. There are two storage tiers:
- Runtime globals: In-memory only, lost when the appliance restarts
- Persisted globals: Saved to disk, survive appliance restarts
Key Features
| Feature | Description |
|---|---|
| Cross-Script Communication | Share data between different scripts |
| JSON Support | Store any JSON-serializable value (strings, numbers, objects, arrays) |
| Flat Namespace | Simple key-value storage accessible to all scripts |
| Two-Tier Storage | Runtime (fast, temporary) and persisted (survives restarts) |
| GUI Management | View and edit globals from the Automation dialog |
Setting Global Variables
setGlobal(key, value, options) / set_global(key, value, persist=False)
Set a global variable on the appliance.
| Parameter | Type | Description |
|---|---|---|
key | string | Variable name (non-empty string) |
value | any | JSON-serializable value |
options.persist | boolean | Save to disk (survives restarts). Default: false |
Returns: true if successful
// Set a runtime global (lost on restart)
await oloClient.core.setGlobal('robotSpeed', 0.5);
// Set a global with complex data
await oloClient.core.setGlobal('waypoints', [
{ x: 1, y: 2, name: 'kitchen' },
{ x: 3, y: 4, name: 'living-room' }
]);
// Set a persisted global (survives restarts)
await oloClient.core.setGlobal('defaultSpeed', 0.3, { persist: true });Getting Global Variables
getGlobal(key) / get_global(key)
Get a single global variable.
| Parameter | Type | Description |
|---|---|---|
key | string | Variable name |
Returns: The value, or undefined/None if not set
const speed = await oloClient.core.getGlobal('robotSpeed');
if (speed !== undefined) {
console.log('Current speed:', speed);
} else {
console.log('Speed not set, using default');
}getAllGlobals() / get_all_globals()
Get all global variables as an object/dictionary.
Returns: Object/dictionary with all key-value pairs
const allGlobals = await oloClient.core.getAllGlobals();
console.log('Current globals:', allGlobals);
// Iterate over globals
for (const [key, value] of Object.entries(allGlobals)) {
console.log(` ${key}: ${JSON.stringify(value)}`);
}Deleting Global Variables
deleteGlobal(key, options) / delete_global(key, persist=False)
Delete a global variable.
| Parameter | Type | Description |
|---|---|---|
key | string | Variable name |
options.persist | boolean | Also remove from persisted storage. Default: false |
Returns: true if the key existed
// Delete from runtime only
const existed = await oloClient.core.deleteGlobal('temporaryFlag');
// Delete from both runtime and persisted storage
await oloClient.core.deleteGlobal('oldConfig', { persist: true });clearGlobals(options) / clear_globals(persist=False)
Clear all global variables.
| Parameter | Type | Description |
|---|---|---|
options.persist | boolean | Also clear persisted storage. Default: false |
Returns: Object with runtimeCleared and persistedCleared counts
// Clear runtime globals only
const result = await oloClient.core.clearGlobals();
console.log(`Cleared ${result.runtimeCleared} runtime globals`);
// Clear all globals including persisted
const fullClear = await oloClient.core.clearGlobals({ persist: true });
console.log(`Cleared ${fullClear.runtimeCleared} runtime, ${fullClear.persistedCleared} persisted`);Cross-Script Communication Example
Global variables enable powerful patterns for script coordination:
Configuration Script:
// setup-patrol.js - Run once to configure patrol settings
await oloClient.core.setGlobal('patrolConfig', {
rooms: ['kitchen', 'living-room', 'bedroom'],
interval: 300000, // 5 minutes between patrols
alertOnMotion: true
}, { persist: true });
console.log('Patrol configuration saved');Patrol Script:
// patrol.js - Uses configuration from globals
const config = await oloClient.core.getGlobal('patrolConfig');
if (!config) {
throw new Error('Patrol not configured. Run setup-patrol first.');
}
for (const room of config.rooms) {
console.log(`Patrolling ${room}...`);
await oloClient.nav.navigateTo(`${room}-waypoint`);
await oloClient.core.abortableDelay(2000);
}
// Update last patrol time
await oloClient.core.setGlobal('lastPatrolTime', new Date().toISOString());Status Script:
// status.js - Check patrol status
const lastPatrol = await oloClient.core.getGlobal('lastPatrolTime');
const config = await oloClient.core.getGlobal('patrolConfig');
if (lastPatrol) {
const elapsed = Date.now() - new Date(lastPatrol).getTime();
const minutesAgo = Math.round(elapsed / 60000);
console.log(`Last patrol: ${minutesAgo} minutes ago`);
if (elapsed > config?.interval) {
console.log('WARNING: Patrol overdue!');
}
} else {
console.log('No patrols completed yet');
}GUI Management
Global variables can also be managed from the Automation dialog in the OLO web interface:
- Open the Automation dialog (from robot card or SDK Playground)
- Click the "Globals" button in the header
- View all current global variables
- Add new variables with the "Add" button
- Edit existing variables by clicking the edit icon
- Delete individual variables or clear all
Variables set through the GUI are always persisted to disk.
