Assignment

From NWN Lexicon
Jump to navigationJump to search

Assignments are used to assign the value of a variable or statement to that of another variable or statement. Assignments also allow some shortcuts; see the example below.

// assignment shortcut
void main()
{
    string sExample = "This is an ";
    sExample += "example";
    // functionally equivalent to typing
    // sExample = sExample + "example";
}

Arithmetic Assignments

These symbols can perform assignments on float and/or int data types.

Symbol Operation Description
= Assignment Assigns the value of an expression to a variable.
+= Assignment Addition Assigns the value of the variable being assigned to incremented by a number.
/= Assignment Division Assigns the value of the variable being assigned to divided by a number.
%= Assignment Modulo Assigns the value of the variable being assigned to modulo by a number.
*= Assignment Mulitplication Assigns the value of the variable being assigned to multiplied by a number.
-= Assignment Subtraction Assigns the value of the variable being assigned to subtracted by a number.

String Assignments

These symbols can perform assignments on the string data type.

Symbol Operation Description
= Assignment Assigns the value of an expression to a string variable.
+= Assignment Concatenation Assigns the value of the variable being assigned concatenated with an expression.

Bitwise Assignments

These symbols can perform assignments on the int data type.

Symbol Operation Description
= OR Assignment Assigns the value of the variable being assigned bitwise OR'd with an expression.
&= AND Assignment Assigns the value of the variable being assigned bitwise AND'd with an expression.
^= XOR (exclusive OR) Assignment Assigns the value of the variable being assigned bitwise XOR'd with an expression.
<<= Shift Left Assignment Assigns the value of the variable being assigned shifted left (multiple) by an expression.
>>= Shift Right Assignment Assigns the value of the variable being assigned shifted right (divided) by an expression.
>>>= Shift Right Zero Fill Assignment Assigns the value of the variable being assigned shifted right (divided) by an expression, but discarding values shifted off the right side of the resulting value and padding the left side with zeros ("0").

See Also

constants:  Arithmetic and String Operators, Bitwise Operators



author: Charles Feduke, additional contributor(s): Ryan Hunt