Are Optoscript string expressions limited as to where they can be used?

I am trying to transmit a string in an Optoscript block with an appended newline.

I get a syntax error at or near "+" with this:

ReturnStatus = TransmitString( RobotCommand + Chr(13), CH);

or this:

ReturnStatus = TransmitString( (RobotCommand + Chr(13)), CH);

Here is my work-around:

RobotCommand = RobotCommand + Chr(13);
ReturnStatus = TransmitString(RobotCommand, CH);

(Note – RobotCommand is a string variable and ReturnStatus is an Int32 variable).

I know that the ‘+’ is not a problem, as this compiles OK:

NumberToHexString(CommandLength + 4, RobotResponse);

Does Optoscript have limitations on where string expressions can be used?

Yes.

The “+” operator is actually a different instruction for strings than it is for numeric values. It is the Optoscript version of “Append String to String” and “Append Character to String” commands.

I imagine the limitation of not being able to concatenate strings in command parameters is due to the way memory is allocated for strings - with an integer or float the result gets placed on the stack like a literal so it’s no big deal (it’s 4 bytes (or 8) no matter what happens), whereas a string concatenation the result needs to have memory allocated to it due to a strings varying length. Since Optoscript has no dynamic memory allocation, there is nowhere for the string result to be stored - so you must assign the result to a variable, which is essentially a compile time memory allocation of whatever size you defined the string variable.

What is really annoying is you can do things like this:

MyString += MyOtherString;

but not:

MyInteger += 5;