MCL Scripting: Variables


This introduction to the MCL programming language for the MCP motor controller line covers the different types of variables available when writing MCL scripts.


Comments in MCL scripts are denoted by the “;” character. The interpreter will not process anything following the charcter as code. All comments are single line only, each line of multi-line comments must start with the “;” character.
; this is a comment
; multiple
; line
; comment


Variables, which are used to store values, are declared with the following format:
variable_name VAR variable_type
Where variable_name is the name of the variable, VAR is the keyword for declaring a variable and variable_type being the type of the variable. See the table below for a list of variable types that can be used.

Type Bits Value Range
Bit 1 1 or 0
Nib 4 0 to 15
Byte 8 0 to 255
SByte 8 -128 to +127
Word 16 0 to 65,535
SWord 32 -32,768 to +32,767
Long 32 0 to 4,294,967,295
SLong 32 -2,147,483,647 to +2,147,483,648
Float 32 ± 2.0 EXP -126 to ± 2.0 EXP 127

first VAR Byte ; an 8-bit byte variable delcared
second VAR Word ; a 16-bit word variable declared
third VAR Float ; a 32-bit floating point variable declared

Variable Names

Variable names must start with a a letter and can be any number of letters and character, except for those in the reserved list used by the interpreter (see manual). The maximum length of a variable name is 1,024 characters.

Variable Assignment

Values are stored in variables by using the equals sign operator “=”. The variable name is written on the left-hand side and the value or expression written on the right-hand side. See the box below for examples.

first VAR byte
first = 1; storing a value of 1 in the variable named first
first = first + 1; the expression “first + 1”, which evaluates to 2, is stored in the variable first. The value of first is now 2.


Constants are named variables that store values that will not change while the program is running. There are two types of constants, the normal variety which is useful for storing integers and declared with the CON keyword, and the floating point variety defined with the keyword FCON.

count CON 200
familiar FCON 3.16


Arrays are used to hold multiple instances of a particular variable type. The values are stored together in a contiguous region of memory and can be accessed by an index value. They are declared by adding a size value to the variable type in when declating the variable. See the box below for some examples.

someValues VAR Byte(4) ; this declares an array of 4 bytes values named someValues
someBits VAR Bit(10) ; this declares an array of 10 bit values named someBits

To write to a location in the array an index is used along with the name of the array. The index numbering starts at zero and end with one less than the size of the array. See the box below for an example.

someValues(0) = 100 ; 100 is stored in the first location in the array
someBits(9) = 1 ; 1 is stored at the very end of the array

Constant Tables

Constant tables are similar to arrays but are used to store constant values in an array style format. They are declared with the followining format:
variable_name type value
Where avriable_name is the name of the variable, type if the type of data to store and value is the actual data to store in the constant table. The type can be one of the types in the table below.

Type Size
ByteTable Each table index point is byte sized (8 bits).
SByteTable Each table index point is sbyte sized(signed 8 bits).
WordTable Each table index point is word sized (16 bits).
SWordTable Each table index point is sword sized(signed 16 bits).
LongTable Each table index point is long sized (32 bits).
SLongTable Each table index point is slong sized (32 bits).
FloatTable Each table index point is floating point sized (32 bits).

hello ByteTable “Hello, world!” ; byte table to store a string
hello(0) ; this evaluates to the character “H”