A B C D E F G I J K L M N O R S T U V W

The most common arithmetic operation is assignment, denoted with the “=” sign (single equal sign). Loosely translated, it means, take what is found on the right side of the equal sign and assign it to the left side. Any expression that evaluates to a basic type can be used as the right side of an assignment, but the left side must be a normal variable.

The type of the value must agree with the declared type of the variable or the compiler will complain. You may convert the value to the correct type with a typecast.

All basic types support the assignment “=” operator.

// variables to hold a information about the target
key g_target;
vector g_target_postion;
float g_target_distance;

// function that demonstrates assignment
set_globals(key target, vector pos)
{
    g_target = target;
    g_target_position = pos;

    // assignment from the return value of a function
    vector my_pos = llGetPos(); 
    g_target_distance = llVecDist(g_target_position, my_pos);
}

Note: Like many other languages, LSL supports combining the assignment operator with binary operators.

Operator Syntax Description
= var1 = var2 Assigns the value var2 to the variable var1.
+= var1 += var2 Assigns the value var1 + var2 to the variable var1.
-= var1 -= var2 Assigns the value var1 - var2 to the variable var1.
*= var1 *= var2 Assigns the value var1 * var2 to the variable var1.
/= var1 /= var2 Assigns the value var1 / var2 to the variable var1.
%= var1 %= var2 Assigns the value var1 % var2 to the variable var1.

Note: Do not confuse the assignment operator “=” with the equality operator “==”! The compiler will not catch the error, and doing so will always cause the statement to evaluate to TRUE; or will cause the conditional variable to become corrupted.

Other types of operators:
unary, binary, bitwise, boolean

 

Credit to: Lslwiki.net (not working) with changes made for brevity and clarity.