Global Variables
JavaScript and Python variables are private to each script engine’s namespace. In other words, a variable created in one JavaScript or Python script does not automatically exist in another script. For example, variables declared in the JavaScript or Python for the Camera control are not accessible from the JavaScript or Python for the WiiMote control. If you need to share data between scripts, use ARC’s global variable storage.
Access Public/Global Variables
Public variables are stored in ARC’s global variable manager, which is shared across all robot skills and compilers. You can access these variables from JavaScript and Python using the getVar(), setVar(), setVarObject(), and varExists() commands. Refer to the JavaScript or Python documentation for the exact syntax and usage details.
Commands
setVar( "$variableName", value )— Creates or updates a global variable. If the value is an array, a global array variable is created. If the value is a boolean, it is stored as1(true) or0(false).setVar( "$variableName", value, "description" )— Same as above, with an optional human-readable description. See the Variable Description section below.setVarObject( "$variableName", value )— Stores a deep copy of the supplied object as the global variable. Use this when the value is a complex object that should not be changed by later script activity. The stored variable is an independent clone, not a reference.setVarObject( "$variableName", value, "description" )— Same assetVarObject()above, with an optional description.getVar( "$variableName" )— Returns the current value of the global variable. Strings are returned unquoted, numbers are returned as numeric values, and arrays are returned as arrays. You may also index directly into an array, for example:getVar( "$myArray[2]" ).getVar( "$variableName", defaultValue )— Returns the variable’s value if it exists; otherwise, returns the supplied default value. Use this to avoid errors when a variable may not yet be defined.varExists( "$variableName" )— Returnstrueif the global variable has been defined; otherwise, returnsfalse.
Variable Description
The optional third parameter of setVar() and setVarObject() is a description string. This is a short, human-readable note that explains what the variable is used for. ARC stores the description alongside the variable in the global variable manager, and it appears in the Variable Watcher and variable dump output. This makes it easier for you and anyone else reading the project to understand the purpose of each variable at a glance.
Notes about the description parameter:
- The description is optional. If omitted, the variable is created or updated without changing any existing description.
- If you call
setVar()again with a new non-empty description, the stored description is updated. Passing an empty string leaves any existing description unchanged. - The description does not affect the variable’s value or behavior. It is informational only.
Example in JavaScript:
setVar( "$BatteryLevel", 87, "Current battery percentage reported by the robot" );
setVar( "$LastUserName", "Sarah", "Name of the most recently recognized user" );
setVarObject( "$LastDetection", detectionObject, "Most recent object detected by the camera" );
Blockly
Blockly generates JavaScript, so variables are private by default. To make a variable public, begin its name with a $ (dollar sign).
Default Variables
A few global variables are reserved for specific functions within ARC’s internal framework. These variables are initialized when ARC starts and are updated when key framework components change, such as movement direction, speed, audio playback, and speech status.
$Direction— The current direction the robot has been instructed to move. The movement manager handles this variable. When any robot skill instructs movement, the current movement panel responds by moving the robot in that direction.$EZBPlayingAudio— Set totruewhen the EZ-B is playing audio through the audio stream, such as an MP3 or WAV from a soundboard. When no audio is playing, this variable isfalse.$IsSpeaking— Set totruewhen theSay()orSayEZB()commands are executed. Otherwise, it is set tofalse.$NavigationStatus— Stores the current navigation status while the Navigation Manager System (NMS) is navigating. This is used by navigation skills such as The Better Navigator for SLAM waypoint navigation.$SpeakingText— Works with$IsSpeakingby holding the current text being spoken. When nothing is being spoken, this variable is cleared and set to an empty string ("").