MCL Scripting: Output Modifiers

What is an Output Modifier?

Output modifiers are used to modify the output format of a variable when it is passed to the puts function for printing or transmission to external hardware. They are most commonly used to output ASCII representations of numerical values.

Output Modifiers

DEC Decimal

The DEC modifier converts an integer value to it’s ASCII representation.

Format:
DEC{#max} expression{\#min}

#max: optional maximum number of digits to send
#min: optional minimum number of digits to send

Example:

num var word
num = 1234
puts 0,[DEC num] ; print “1234”

SDEC Signed Decimal

The SDEC modifier converted a signed integer to it’s ASCII representation.

Format:
SDEC{#max} expression{\#min}

#max: optional maximum number of digits to send
#min: optional minimum number of digits to send

Example:

num var sword
num = -1234
puts 0,[SDEC num] ; prints “-1234”

HEX Hexidecimal

The HEX modifier converts a value stored in hexidecimal to it’s ASCII representation.

Format:
HEX{#max} expression{\#min}

#max: optional maximum number of digits to send
#min: optional minimum number of digits to send

Example:

num var word
num = 0x12ab
puts 0,[HEX num] ; prints “0x12ab”

IHEX Indicated ($) Hexadecimal

The IHEX modifier converts a value stored in hexidecimal to it’s ASCII representation.

Format:
IHEX{#max} expression{\#min}

#max: optional maximum number of digits to send
#min: optional minimum number of digits to send

Example:

num var word
num = 0x12ab
puts 0,[IHEX num] ; prints “$12ab”

REP Repeat Character N Times

The REP modifier repeats a character a number of specified times.

Format:
REP {character}\# of times to repeat

Example:

puts 0,[REP “A”\10] ; prints “AAAAAAAAAA”

REAL Floating Point Number with Decimal Point

The REAL modifier converts a floating point value to it’s ASCII representation.
Format:

REAL{#maxint} expression{\#maxdec}
#maxint: optional maximum number of integer digits to send
#maxdec: optional maximum number of decimal point digits to send

Example:

num var float
num = 3.142
puts 0,[REAL num] ; prints “3.142”

STR Write Specified Number of Character

The STR modifier takes a specified number of characters from a string for use in an output command such as puts.

Format:
STR array\length{\eol}

Length: number of characters to copy
EOL: end of line character to stop on

Example:

phrase var byte(20)
phrase = “Hello, world!”,0
puts 0,[STR phrase\20\0] ; prints “Hello, world!”