DAZ Script Operators

Arithmetic Operators
Symbol Description
++ Increment
-- Decrement
* Multiplication
/ Division
% Modulus (Remainder)
+ Addition
- Subtraction (Negation)
Binary Bitwise Operators
Symbol Description
<< Binary Left Shift
>> Binary Right Shift (Signed)
>>> Binary Right Shift (Unsigned)
& Binary AND
^ Binary XOR (Exclusive)
| Binary OR (Inclusive)
~ Binary NOT (Negation)
[Compound] Assignment Operators
Symbol Description
= Simple Assignment
*= Multiplication Assignment
/= Division Assignment
%= Modulus (Remainder) Assignment
+= Addition Assignment
-= Subtraction Assignment
<<= Binary Left Shift Assignment
>>= Binary Right Shift Assignment (Signed)
>>>= Binary Right Shift Assignment (Unsigned)
&= Binary AND Assignment
^= Binary XOR Assignment (Exclusive)
|= Binary OR Assignment (Inclusive)
Logical Operators
Symbol Description
< Less-than
> Greater-than
<= Less-than-or-equal
>= Greater-than-or-equal
== Equals
!= Does-not-equals
=== Strict Equals
!== Strict Does-not-equals
&& Logical AND
|| Logical OR (Inclusive)
! Logical NOT (Negation)
?: Conditional (Ternary)
, Comma
Special Operators
Keyword
function
in
instanceof
new
delete
this
typeof
@todo EXAMPLES

Arithmetic Operators

These operators are used to perform arithmetic computations.

Increment

++
This operator increases the value of a variable by 1.
Example:
var nTmp = 33;
nTmp ++;
// nTmp: 34

Decrement

--
This operator decreases the value of a variable by 1.
Example:
var nTmp = 33;
nTmp --;
// nTmp: 32

Multiplication

*
This operator multiplies the value of one expression by the value of another.
Example:
var nTmp = 33 * 5;
// nTmp: 165

Division

/
This operator divides the value of one expression by the value of another.
Example:
var fTmp = 33 / 5;
// fTmp: 6.6

Modulus (Remainder)

%
This operator divides the value of one expression by the value of another, and returns the remainder.
Example:
var nTmp = 33 % 5;
// nTmp: 3

Addition

+
This operator adds the value of one expression to the value of another.
Example:
var nTmp = 33 + 5;
// nTmp: 38

Subtraction (Negation)

-
This operator subtracts the value of one expression from the value of another, or provides unary negation of an expression.
Example:
var nTmp = 33 - 5;
// nTmp: 28

var nTmp = -33;


Binary Bitwise Operators

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  
BYTE 3 BYTE 2 BYTE 1 BYTE 0 1 BYTE = 8 BIT
WORD 1 WORD 0 1 WORD = 2 BYTE = 16 BIT
DWORD 1 DWORD = 2 WORD = 4 BYTE = 32 BIT

These operators are used to perform bitwise operations on the binary representation of numbers (32-bit).

Binary Left Shift

<<
This operator performs a bitwise left shift on the value of an expression by the number of bits specified in the value of another expression, and returns it.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
nTmp = nTmp << 2;
// nTmp: 52 // 00000000 00000000 00000000 00110100

Binary Right Shift (Signed)

>>
This operator performs a bitwise (sign-preserving) right shift on the value of an expression by the number of bits specified in the value of another expression, and returns it. Digits shifted off the right are discarded.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
nTmp = nTmp >> 2;
// nTmp: 3 // 00000000 00000000 00000000 00000011

Binary Right Shift (Unsigned)

>>>
This operator performs a bitwise (zero-padding) right shift on the value of an expression by the number of bits specified in the value of another expression, and returns it. Digits shifted off the right are discarded.

Example:
var nTmp = -13;// 11111111 11111111 11111111 11110011
nTmp = nTmp >>> 2;
// nTmp: 1073741820 // 00111111 11111111 11111111 11111100

Binary AND

&
This operator performs a bitwise AND on the value of two expressions, and returns it. Looking at the binary representation of the expressions, any time both have a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp = nTmp & nTmp2;
// nTmp: 9 // 00000000 00000000 00000000 00001001

Binary XOR (Exclusive)

^
This operator performs a bitwise exclusive OR on the value of two expressions, and returns it. Looking at the binary representation of the expressions, any time only one has a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp = nTmp ^ nTmp2;
// nTmp: 6 // 00000000 00000000 00000000 00000110

Binary OR (Inclusive)

|
This operator performs a bitwise OR on the value of two expressions, and returns it. Looking at the binary representation of the expressions, any time either one has a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp = nTmp | nTmp2;
// nTmp: 15 // 00000000 00000000 00000000 00001111

Binary NOT (Negation)

~
This operator performs a bitwise NOT (negation) on the value of an expression. Digits that are 1 become 0 and vice versa.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = ~nTmp;
// nTmp2: -14 // 11111111 11111111 11111111 11110010


[Compound] Assignment Operators

These operators are used to assign values of expressions to variables.

Simple Assignment

=
This operator assigns the value of an expression to a variable.

Example:
var sTmp = "Temp";

var nTmp = 5;

var oTmp = new Object;

Multiplication Assignment

*=
This operator mulitplies the value of an expression by the existing value of a variable, and assigns it to the variable.

Example:
var nTmp = 5;
nTmp *= 2;
// nTmp: 10

Division Assignment

/=
This operator divides the value of an expression by the existing value of a variable, and assigns it to the variable.

Example:
var nTmp = 5;
nTmp /= 2;
// nTmp: 2.5

Modulus (Remainder) Assignment

=
This operator divides the value of an expression by the existing value of a variable, and assigns the remainder to the variable.

Example:
var nTmp = 5;
nTmp %= 2;
// nTmp: 1

Addition Assignment

+=
This operator adds the value of an expression to the existing value of a variable, and assigns it to the variable.

Example:
var sTmp = "Temp";
var sTmp2 = "String";
sTmp += sTmp2;
// sTmp: "TempString"

var nTmp = 5;
nTmp += 2;
// nTmp: 7

Subtraction Assignment

-=
This operator subtracts the value of an expression from the existing value of a variable, and assigns it to the variable.

Example:
var nTmp = 5;
nTmp -= 2;
// nTmp: 3

Binary Left Shift Assignment

<<=
This operator performs a bitwise left shift on the existing value of a variable by the number of bits specified in the value of an expression, and assigns it to the variable.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
nTmp <<= 2;
// nTmp: 52 // 00000000 00000000 00000000 00110100

Binary Right Shift Assignment (Signed)

>>=
This operator performs a bitwise (sign-preserving) right shift on the existing value of a variable by the number of bits specified in the value of an expression, and assigns it to the variable. Digits shifted off the right are discarded.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
nTmp >>= 2;
// nTmp: 3 // 00000000 00000000 00000000 00000011

Binary Right Shift Assignment (Unsigned)

>>>=
This operator performs a bitwise (zero-padding) right shift on the existing value of a variable by the number of bits specified in the value of an expression, and assigns it to the variable. Digits shifted off the right are discarded.

Example:
var nTmp = -13;// 11111111 11111111 11111111 11110011
nTmp >>>= 2;
// nTmp: 1073741820 // 00111111 11111111 11111111 11111100

Binary AND Assignment

&=
This operator performs a bitwise AND on the value of an expression and the existing value of a variable, and assigns it to the variable. Looking at the binary representation of the variable value and the expression, any time both have a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp &= nTmp2;
// nTmp: 9 // 00000000 00000000 00000000 00001001

Binary XOR Assignment (Exclusive)

^=
This operator performs a bitwise exclusive OR on the value of an expression and the existing value of a variable, and assigns it to the variable. Looking at the binary representation of the variable value and the expression, any time only one has a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp ^= nTmp2;
// nTmp: 6 // 00000000 00000000 00000000 00000110

Binary OR Assignment (Inclusive)

|=
This operator performs a bitwise OR on the value of an expression and the existing value of a variable, and assigns it to the variable. Looking at the binary representation of the variable value and the expression, any time either one has a 1 in the digit, a 1 is returned, otherwise a 0 is returned for that digit.

Example:
var nTmp = 13;// 00000000 00000000 00000000 00001101
var nTmp2 = 11;// 00000000 00000000 00000000 00001011
nTmp |= nTmp2;
// nTmp: 15 // 00000000 00000000 00000000 00001111


Logical Operators

Logical operators are used to evaluate whether operands are true or false in terms of the operator (in the case of !) and in terms of each other (in the cases of && and ||). The binary operators (&& and ||) use short-circuit logic, meaning they do not evaluate the second operand if the logical value of the expression can be determined by evaluating the first operand.

Non-boolean values are converted, for evaluation, such that an Object is always true, a String is true unless it is empty ("") or has not been initialized (in which case it is undefined and thus false), and a Number is true unless the value is 0.

Less-than

<
This operator tests if one operand is less than another.

Example:
var nTmp = 13;
var nTmp2 = 11;

if( nTmp < nTmp2 ){// false; 13 is greater than 11
    // ...statements;
}

Greater-than

>
This operator tests if one operand is greater than another.

Example:
var nTmp = 13;
var nTmp2 = 11;

if( nTmp > nTmp2 ){// true; 13 is greater than 11
    // ...statements;
}

Less-than-or-equal

<=
This operator tests if one operand is less than or equal to another.

Example:
var nTmp = 13;
var nTmp2 = 11;

if( nTmp <= nTmp2 ){// false; 13 is greater than 11
    // ...statements;
}

Greater-than-or-equal

>=
This operator tests if one operand is greater than or equal to another.

Example:
var nTmp = 13;
var nTmp2 = 11;

if( nTmp >= nTmp2 ){// true; 13 is greater than 11
    // ...statements;
}

Equals

==
This operator tests if one operand is equal to another. If types of the operands differ, an attempt at coercion is made.

Example:
var bTmp = true;
var bTmp2 = false;

if( bTmp == bTmp2 ){// false; true != false
    // ...statements;
}

Does-not-equals

!=
This operator tests if one operand is NOT equal to another. If types of the operands differ, an attempt at coercion is made.

Example:
var bTmp = true;
var bTmp2 = false;

if( bTmp != bTmp2 ){// true; true != false
    // ...statements;
}

Strict Equals

===
This operator tests if one operand is equal to another. If types of the operands differ, no attempt at coercion is made, and the result is false.

Example:
var bTmp = true;
var bTmp2 = false;

if( bTmp === bTmp2 ){// false; true != false
    // ...statements;
}

Strict Does-not-equals

!==
This operator tests if one operand is NOT equal to another. If types of the operands differ, no attempt at coercion is made, and the result is false.

Example:
var bTmp = true;
var bTmp2 = false;

if( bTmp !== bTmp2 ){// false; same type, Boolean
    // ...statements;
}

Logical AND

&&
This operator performs logical conjunction on two operands. If, and only if, both operands evaluates true, true is returned; otherwise false is returned.

Example:
var bTmp = true;
var nTmp;

if( bTmp && nTmp ){// false; nTmp is undefined
    // ...statements;
}

Logical OR (Inclusive)

||
This operator performs logical disjunction on two operands. If either operand evaluates true, true is returned; otherwise false is returned.

Example:
var bTmp = true;
var nTmp;

if( bTmp || nTmp ){// true; bTmp is true
    // ...statements;
}

Logical NOT (Negation)

!
This operator performs logical negation on an expression.

Example:
var bTmp = false;

if( !bTmp ){// true; !bTmp is true
    // ...statements;
}

Conditional (Ternary)

?:
This operator can be used as a shortcut for an if...else statement.

Example:
// EXAMPLE NEEDED

Comma

,
Causes to expressions to be executed sequentially. Expressions separated by a comma are executed left-to-right and the value of the right-most expression is taken as the final result. A common use of the comma operator is in the for() loop.

Example:
var i, j;

for( i = 0, j = 10; i < j; i++, j-- ){
    print( i );
    print( j );
}


Special Operators

These operators perform functions unique to the DAZ Script language

function

The function operator declares a new script function.

Example:
function myFunction(){
    print( "hello" );
}

in

This operator tests for the existence of a property in an object.

Example:
// EXAMPLE NEEDED

instanceof

This operator returns true if an Object is an instance of the given object.

Example:
// Function Object
function Point3( px, py, pz ) {
    this.x = px;
    this.y = py;
    this.z = pz;
}

// create a new Point3 Object
var oPoint = new Point3( 1, 2, 3 );

if( oPoint instanceof Point3 )
    MessageBox.information( "oPoint is an instance of Point3.", "instanceof Operator", "&OK" );

Attention:
Due to the manner in which SDK classes must be exposed to scripting (an imposition by Qt/QtScript), only the ECMAScript/QtScript - Native Objects and any objects declared/defined in script can use the instanceof operator. For all other objects, you must use the methods under the DAZ Script documentation for the QObject class.

new

This operator creates a new instance of an object.

Example:
// Function Object
function Point3( px, py, pz ) {
    this.x = px;
    this.y = py;
    this.z = pz;
}

// Create a new Point3 Object
var oPoint = new Point3( 1, 2, 3 );

delete

This operator destroys an object.

Example:
// EXAMPLE NEEDED

this

The this operator should only be used within a function. In a function, the this operator is used to refer to that specific instance (object) of the function to access functions (methods) and/or variables that are properties of that specific instance of the function object. Using the this operator allows you to declare function objects that can be instanciated multiple times and act like classes.

Example:
// Function Object
function Point3( px, py, pz )
{
    // Assign the passed-in variables as properties of the function object
    this.x = px;
    this.y = py;
    this.z = pz;
}

// Create a new Point3 Object
var oPoint = new Point3( 1, 2, 3 );

// Create another new Point3 Object with different values
var oPoint2 = new Point3( 4, 5, 6 );

// Display the values of the first Point3
debug( oPoint.x );
debug( oPoint.y );
debug( oPoint.z );

// Display the values of the second Point3
debug( oPoint2.x );
debug( oPoint2.y );
debug( oPoint2.z );

typeof

This operator returns a String representing the type of an object. There are six possible strings returned: "number", "string", "boolean", "object", "function" and "undefined"

Example:
var nTmp = 33;
// typeof nTmp == "number"
var fTmp = 33.5;
// typeof fTmp == "number"
var sTmp = "Temp";
// typeof sTmp == "string"
var bTmp = true;
// typeof bTmp == "boolean"
var oTmp = new Object;
// typeof oTmp == "object"
var funcTmp = new Function( "arguments[0]*2" );
// typeof funcTmp == "function"
var Tmp;
// typeof Tmp == "undefined"


Generated on Thu Sep 24 12:21:06 2009

Copyright © 2002 - 2009 DAZ 3D, Inc.