Operators

 

Arithmetic Assignment

=(assignment)
True if the preceding variable can take the value of 1.
Example:
if(j=1)
{
    // j=1 from now on.
}

+= (add assign)
This operator adds the variable to the value and stores it in the variable. .
Example:
A=4;
A+=2;    // A is now 6

Linear arrays can now be appended (or created) using the overloaded '+=' assignment operator. When applied to an existing array, the data being added is placed into a new element at the end of the existing linear list of elements:

a[1] = "Bob";
a[2] = 1.0;
a += <1,2,3>; // placed into a[3]

In addition, new linear arrays can be generated automatically when the overloaded '+=' oeprator is used with a variable containing a 'nil' value:

vmapnames = nil;
while(vmap)
{
vmapnames += vmap.name;
vmap = vmap.next();
}

Because LScript automatically initializes unused variables with a 'nil' value, the explicit assignment of 'nil' illustrated in the code fragment above is only necessary if the variable contains a value other than 'nil', or is already hosting an existing array.

-= (subtract assign)
This operator subtracts the value from the variable and stores it in the variable. .
Example:
A=4;
A-=1;    // A is now 3

*= (multiply assign)
This operator multiplies the value to the variable and stores it in the variable. .
Example:
A=4;
A*=3;    // A is now 12

/= (divide assign)
This operator divides the value into the variable and stores it in the variable. .
Example:
A=8;
A*=2;    // A is now 4

%= (modulo assign)
This operator divides the value into the variable and stores the remainder in the variable. .
Example:
A=4;
A*=3;    // A is now 1

++ (increment assign)
This operator adds 1 to the variable and stores the result in the variable. If it used before the variable, the variable is incremented THEN used. If it is used after, the variable is used THEN incremented.
Example:
A=4;
B=A++;    // B=4, while A is now 5
C=++A;    // C and A are both 6

-- (decrement assign)
This operator subtracts 1 from the variable and stores the result in the variable. If it used before the variable, the variable is incremented THEN used. If it is used after, the variable is used THEN incremented.
Example:
A=4;
B=A--;    // B=4, while A is now 3
C=--A;    // C and A are both 2

Maths Operators

+ (Add)
This operator adds two numerical values, or appends two strings, or appends one array to another.
Example:
x=1;
y=2;
z=x+y; //z now equals 3;

- (Subtract)
This operator subtracts two numerical values.
Example:
x=4;
y=1;
z=x-y; //z now equals 3;

* (Multiply)
This operator multiplies two numerical values.
Example:
x=4;
y=5;
z=x*y; //z now equals 20;

/ (Divide)
This operator divides two numerical values.
Example:
x=10;
y=5;
z=x/y; //z now equals 2;

^^ (Power)
This operator raises the first operand to the power of the second operand
Example:
x=2;
y=5;
z=x^^y; //z now equals 32;

% (Modulo)
The % operator returns the modulo—or remainder—of the division when its first numeric argument is divided by its second.
Example:
x=5;
y=2;
z=x%y; //z now equals 1;

Conditional Operators
Equality testing in Lscript allows for dissimilar type comparisons. When comparisons take place ('==', '<'etc.), the second comparitor is converted to be of an equivalent data type as that of the first (if it is not already).

anumber = 1.5;
astring = "43.34";

if(anumber == astring) // 'astring' is converted into
{ // a number for the comparison
...

if(astring == anumber) // 'anumber' is converted into
{ // a string for the comparison

Be aware that, in some less conventional comparisons, you may get results that differ depending upon which comparitor appears first. In cases where the comparitors are too dissimilar, the results are undefined.

! (invert test)
This operator inverts the condition.
Example:
if(!A)
{
    // Carried out if  A is not true.
}

== (equality test)
This operator tests for equality.
Example:
if(A==B)
{
    // Carried out if  A is equal to B
}

!= (inequality test)
This operator tests for inequality.
Example:
if(A!=B)
{
    // Carried out if  A is NOT equal to B
}

< (less than test)
This operator tests for the less than condition.
Example:
if(A<B)
{
    // Carried out if  A is less than B
}

>(more than test)
This operator tests for the more than condition.
Example:
if(A>B)
{
    // Carried out if  A is more than B
}

<= (less than or equal to test)
This operator tests for the less than or equal to condition.
Example:
if(A<=B)
{
    // Carried out if  A is less than or equal to B
}

>= (more then or equal to test)
This operator tests for the more than or equal to condition.
Example:
if(A>=B)
{
    // Carried out if  A is more than or equal to B
}

Boolean Tests

&& (AND test)
This operator tests for the boolean AND condition.
Example:
if(A && B)
{
    // Carried out if  A AND B are both true.
}

|| (OR test)
This operator tests for the boolean OR condition.
Example:
if(A || B)
{
    // Carried out if  A OR B OR BOTH are true.
}

Bitwise Tests

& (Bitwise AND)
This operator performs a bitwise AND operation on two binary numbers
Example:
1100&1010  // this equals 1000

| (Bitwise OR)
This operator performs a bitwise OR operation on two binary numbers
Example:
1100|1010  // this equals 1110