...
Scroll tablelayout | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
The following sections show you how to work with operators: maxLevel Table of Contents
Scroll only | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||
Scroll pagebreak |
---|
Understand operator types
...
Scroll pagebreak |
---|
Arithmetic operators
Anchor | ||||
---|---|---|---|---|
|
...
Arithmetic operators are symbols that represent mathematic functions.
...
For example, instead of writing the full expression:
Code Block | ||
---|---|---|
| ||
$hammer = $hammer + 3.5; |
You can write the following shortcut:
Code Block | ||
---|---|---|
| ||
$hammer += 3.5; |
Both statements accomplish the same results.
...
These examples show how to use shortcut operators rather than writing out full expressions:
Code Block | ||
---|---|---|
| ||
// Declare variable |
...
int $inside = 1; |
...
...
// Shortcut for expression $inside = $inside + 9 |
...
$inside += 9; |
...
...
// Shortcut for expression $inside = $inside –2 |
...
$inside -= 2; |
...
...
// Shortcut for expression $inside = $inside 10 |
...
$inside *= 10; |
...
print $inside; |
...
...
//declare variable |
...
vector $outside = <<2,2,2>>; |
...
...
// Shortcut for expression $outside += $outside + <<<<1,2,3>> |
...
$outside += <<1,2,3>>; |
...
print $outside; |
Comparison operators
Anchor | ||||
---|---|---|---|---|
|
Comparison operators
...
Comparison operators are used to compare two values and evaluate whether a statement is true based on the relation of the value on the left to the value on the right and then execute the statement accordingly.
...
Note that comparison operators and arithmetic operators can be used in the same statement.
Code Block | ||
---|---|---|
| ||
// Prints "I love you" |
...
float $threshold = 10.0; |
...
if( $threshold < 25.0 ) |
...
print( "I love you" ); |
You can write a hook statement with a comparison operator using three operands.
Examples of comparison expressions
Code Block | ||
---|---|---|
| ||
//true |
...
if (3.5 < 6) print ("true"); |
...
//false |
...
if (10 < 10) print ("true"); |
...
//false |
...
if (56 == 57) print ("true"); |
...
//false |
...
if (-3 != 3) print ("true"); |
...
//true |
...
if (-3 >= -3) print ("true"); |
...
//false |
...
if (0 <= -3) print ("true"); |
Hook statements
A hook statement is written with three operands. The first operand is a test condition that represents true or false. This operand is followed by a question mark ?, then the second and third operands are separated by a colon ( : ).
...
If the test condition is true, the operand after the question mark ?, is used. Otherwise the operand after the colon ( : ) is used. For example:
Code Block | ||
---|---|---|
| ||
test condition ? operation1 : operation2 |
...
int $markers = 5 < 9 ? 40 : 50; // Value: 40 |
Logical operators
Anchor |
---|
...
|
...
Logical operators are used to compare two values and evaluate whether a statement is true or false and then execute the statement accordingly. Logical operators create boolean results, that is, values of either TRUE or FALSE.
...
An expression with a logical operator, also called a logical statement, is written with the first operand followed by a logic symbol, followed by the second operand:
Code Block | ||
---|---|---|
| ||
operand_1 logic_symbol operand_2 |
This table shows the symbols that Shogun Post recognizes as logical operators, defines their function, and indicates how the statement is evaluated as true.
...
Examples of logical operators
Code Block | ||
---|---|---|
| ||
//true |
...
if ( true || false) print ("true"); |
...
//false |
...
if ( true && false) print ("true"); |
...
//false |
...
if (no || no) print ("true"); |
...
//false |
...
if (off || off) print ("true"); |
Determine operator precedence
...
The following sections list operator precedence from highest to lowest and show you how to influence precedence by grouping operators.
Highest precedence
Code Block | ||
---|---|---|
| ||
( ) [ ]
*/ % ^
+ -
< <= > >=
== !=
&& |
...
|| |
...
?: |
...
= += -= *= /= |
Lowest precedence
Examples of when precedence effects the value of a statement:
Code Block | ||
---|---|---|
| ||
//$front = (5 +(2*3)) |
...
int $front = 5 + 2 3 |
...
...
//$side = $side ((8 % 5) / 3) |
...
int $back = 2 - 3 int (1 < 3); |
...
...
//$side = $side ((8 % 5) / 3) |
...
int $side = 2; |
...
$side = 8 % 5 / 3; |
Scroll pagebreak |
---|
Grouping operations for precedence
The order of operation can be manually dictated by placing parentheses around operators. This is because parentheses have highest operator precedence. Examples of dictating precedence:
Code Block | ||
---|---|---|
| ||
//$side = $side (8 % (5 / 3)) |
...
int $side = 2; |
...
$side *= 8 % (5 / 3); |
...
int $top = (5 ( int($side >4))); |