Syntax” refers to the precise format of ScratchLink Commands i.e. the “rules” of how the commands must be written so that the ScratchLink Controller will recognise them as ScratchLink Commands.  ScratchLink Commands have been developed for easy use and understanding by educational users and use everyday English language and simple rules.

ScratchLink Syntax Summary

  1. Space between values and arguments
  2. No space for command device addressing
  3. Terminating semicolon
  4. Multiple commands acceptable
  5. Set order for arguments
  6. Optional arguments
  7. Defaults apply
  8. Symbols:  “[ ]” means optional and “|” means OR 
  9. “value” means whole number input OR anything appended with “Value” eg “pinValue”
command[device] [argument1 value] [argument2 value] [argument3 on|off]; 

ScratchLink Syntax Details & Examples

1. Space between values and arguments and all successive arguments.

Correct syntax:

servo degree 90;

NOT correct syntax:

servo degree90;

2. No space for command device addressing.

Correct syntax:

servo2 degree 90;

NOT correct syntax:

servo 2 degree 90;

3. Terminating semicolon: all commands must have a semicolon “;” at the end.  

Correct syntax:

servo2 degree 90;

NOT correct syntax:

servo2 degree 90

4. Multiple sequential commands acceptable eg:

led blue; servo1 degree 90; wheels drive;

5. Set order for arguments:  arguments cannot be in any order for commands but must be in the specified order for that command.

Correct servo syntax:

servo[device] degree [value] [hold on|off];

Correct example: 

servo2 degree 90 hold yes;

NOT correct example: 

servo2 hold yes degree 90;

6. Optional Arguments:  ScratchLink syntax allows for many command arguments and values to be omitted if not required and are enclosed in square brackets “[ ….]”. 

Generic servo syntax: 

servo[device] degree [value] [hold on|off];

Correct examples: 

servo2 degree 90 hold yes;
servo2 degree 90;
servo degree 90;

NOT correct example: “degree is omitted”

servo2 90;

7. Defaults:  If an argument is optional i.e. […] and none provided, then the default prevails which is defined for each Command but usually means “all devices” for commands and “off” for arguments.

Example:  The following led command has omitted all optional arguments and values so defaults to “all led devices off” and is syntactically correct.


7. Symbols:  “[ ]” means optional and “|” means OR 

Example:  The syntax for “stream” is:

stream [on|off];

This means that an argument is optional and can be either “on” or “off” if provided.  If no argument is provided, then the default applies which is “off”.  So there are 3 valid syntactically correct commands:

stream on;
stream off;

“stream;” is the same as “stream off;” and both are valid as “off” is the default argument for the stream Command.

Further General Examples:  

LED syntax:

led[device] [[color] colorValue] [pixel1...pixeln|pixel_start-pixel_end][bright value];

The following statements are all syntactically correct:

led2 color red 1 5 16 bright 50;
led2 red 1 5 16 bright 50;
led red 1-10 bright 50;
led2 red 1-10;
led2 red;