Built-In
The commands every JavaScript script can use without naming a group, the port names, and the list of connected controllers.
Where to find it: the Built-in section of the ARCx API view in the script editor
Commands
| Command | What it does |
|---|---|
| Writes a line to the console under the editor, and to the log of the robot skill running the script. | |
| printHex | Writes each character of a piece of text to the console as a hexadecimal byte, which is handy for looking at data from a serial device. |
| sleep | Pauses the script for a number of milliseconds. |
| sleepRandom | Pauses the script for a random time between two numbers of milliseconds. |
| halt | Stops this script straight away. |
| getVar | Reads a global variable. |
| setVar | Stores a value in a global variable that every script, robot skill and Custom UI screen can read. |
| setVarObject | Stores a copy of a list or object in a global variable. |
| varExists | Checks whether a global variable exists. |
| deleteVar | Removes a global variable. |
| controlCommand | Asks a robot skill to do something, the same as clicking a button on it. |
| showControl | Brings a robot skill to the front: switches to its workspace and scrolls to it, in every browser looking at the project. |
| showDesktop | Switches every browser looking at the project to a workspace. |
Details
Writes a line to the console under the editor, and to the log of the robot skill running the script.
print(value);
| Value | Type | What it is |
|---|---|---|
value |
any | What to print: text, a number, or anything else. |
printHex
Writes each character of a piece of text to the console as a hexadecimal byte, which is handy for looking at data from a serial device.
printHex(text);
| Value | Type | What it is |
|---|---|---|
text |
any | The text or data to show. |
sleep
Pauses the script for a number of milliseconds. 1000 is one second. A stopped script wakes up straight away.
sleep(ms);
| Value | Type | What it is |
|---|---|---|
ms |
number | How long to wait, in milliseconds. |
sleepRandom
Pauses the script for a random time between two numbers of milliseconds.
sleepRandom(lowMs, highMs);
| Value | Type | What it is |
|---|---|---|
lowMs |
number | The shortest wait, in milliseconds. |
highMs |
number | The longest wait, in milliseconds. |
halt
Stops this script straight away. Nothing after it runs.
halt();
getVar
Reads a global variable. Without a default, reading a variable that does not exist stops the script with an error; with one, the default is given back instead.
getVar(variableName);
getVar(variableName, defaultValue);
| Value | Type | What it is |
|---|---|---|
variableName |
string | The variable's name. The $ at the start is optional, and case does not matter. |
defaultValue |
any | Optional. What to give back when the variable does not exist. |
Gives back: The variable's value.
setVar
Stores a value in a global variable that every script, robot skill and Custom UI screen can read. The variable is created if it does not exist.
setVar(variableName, value);
setVar(variableName, value, description);
| Value | Type | What it is |
|---|---|---|
variableName |
string | The variable's name. The $ at the start is optional, and case does not matter. |
value |
any | The value: a number, text, true or false, a list or an object. |
description |
string | Optional. What the variable is for, shown wherever variables are listed. Leaving it out keeps any description it already has. |
setVarObject
Stores a copy of a list or object in a global variable. With setVar, changing the list afterwards also changes what was stored; setVarObject takes a snapshot, which is what you want when another script will read it.
setVarObject(variableName, value);
setVarObject(variableName, value, description);
varExists
Checks whether a global variable exists.
varExists(variableName);
| Value | Type | What it is |
|---|---|---|
variableName |
string | The variable's name. |
Gives back: boolean. True when the variable exists.
deleteVar
Removes a global variable.
deleteVar(variableName);
| Value | Type | What it is |
|---|---|---|
variableName |
string | The variable's name. |
controlCommand
Asks a robot skill to do something, the same as clicking a button on it. Press Ctrl+Q in the script editor to pick one from a list with its description. ControlCommand, controlcommand, CC and cc are other spellings of the same command.
controlCommand(robotSkill, command, ...values);
| Value | Type | What it is |
|---|---|---|
robotSkill |
string | The robot skill's title, as shown on the workspace. |
command |
string | The name of the command. |
values |
any | Any number of values. What the command needs, if anything. |
Gives back: Whatever the command gives back, if anything; many give back true when they worked.
showControl
Brings a robot skill to the front: switches to its workspace and scrolls to it, in every browser looking at the project.
showControl(windowTitle);
| Value | Type | What it is |
|---|---|---|
windowTitle |
string | The robot skill's title, as shown on the workspace. |
showDesktop
Switches every browser looking at the project to a workspace.
showDesktop(workspaceNumber);
| Value | Type | What it is |
|---|---|---|
workspaceNumber |
number | The workspace, 0 being the first. |
Port names
Commands that take a port take its name, written without quotes. The names are numbers underneath, so a loop can count through them.
| Names | What they are |
|---|---|
d0 to d255 |
Digital ports. An EZB v4 has d0 to d23; servos, digital, PWM, ping and serial commands use them. |
v0 to v255 |
Virtual ports, which servo driver robot skills such as Dynamixel, Feetech or PCA9685 hook to. Servo commands move them like any other servo. |
adc0 to adc255 |
Analog (ADC) inputs. An EZB v4 has adc0 to adc7. |
EZBs
EZBs is the list of controllers in the project, for advanced scripts. Most scripts never need it: the EZB group gives the connection state, voltage and temperature, and commands that use a port take an optional EZB index as their last value.