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

FeatureDescription
Cross-Script CommunicationShare data between different scripts
JSON SupportStore any JSON-serializable value (strings, numbers, objects, arrays)
Flat NamespaceSimple key-value storage accessible to all scripts
Two-Tier StorageRuntime (fast, temporary) and persisted (survives restarts)
GUI ManagementView 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.

ParameterTypeDescription
keystringVariable name (non-empty string)
valueanyJSON-serializable value
options.persistbooleanSave to disk (survives restarts). Default: false

Returns: true if successful

JS
// 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.

ParameterTypeDescription
keystringVariable name

Returns: The value, or undefined/None if not set

JS
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

JS
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.

ParameterTypeDescription
keystringVariable name
options.persistbooleanAlso remove from persisted storage. Default: false

Returns: true if the key existed

JS
// 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.

ParameterTypeDescription
options.persistbooleanAlso clear persisted storage. Default: false

Returns: Object with runtimeCleared and persistedCleared counts

JS
// 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:

JS
// 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:

JS
// 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:

JS
// 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:

  1. Open the Automation dialog (from robot card or SDK Playground)
  2. Click the "Globals" button in the header
  3. View all current global variables
  4. Add new variables with the "Add" button
  5. Edit existing variables by clicking the edit icon
  6. Delete individual variables or clear all

Variables set through the GUI are always persisted to disk.