Arithmetic
+
Add two values
total = a + b;
-
Subtract the right value from the left; unary - negates one value
difference = a - b;
*
Multiply
scaled = value * 125;
/
Integer division; any fractional remainder is discarded
10 / 3 produces 3
%
Remainder after integer division
10 % 3 produces 1
++
Add one
index++;
--
Subtract one
index--;
Prefix changes the variable before the expression result is used; postfix returns the old value and then changes the variable:
b = ++a; // increment a first, then assign the new value to b
b = a++; // assign the old value to b, then increment aPorting an older script?
The original Zen Studio compiler assigned the new value here — b = a++ gave b the incremented value. The current compiler assigns the old value, as described above.
Nothing warns you about this. A script carried over from the older compiler compiles cleanly and quietly computes something different. In a return statement the same difference does produce a warning, GPC6029, but in a plain assignment it does not.
Use the prefix form (b = ++a;) where you want the new value — it behaves identically on both compilers.
Comparison
Comparison operators return true (1) or false (0):
==
Equal to
!=
Not equal to
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
Logical
Logical operators treat zero as false and every nonzero value as true:
!a
Logical NOT: true when a is false
a && b
Logical AND: true when both are true
a || b
Logical OR: true when either is true
a ^^ b
Logical XOR: true when exactly one is true
Bitwise
Bitwise operators work on the individual bits of an integer:
~a
Invert every bit
a & b
Bitwise AND; keep bits set in both values
a | b
Bitwise OR; keep bits set in either value
a ^ b
Bitwise XOR; keep bits set in exactly one value
a << n
Shift bits left by n positions
a >> n
Shift bits right by n positions
Conditional
Zen Studio Live supports the ternary conditional operator. It chooses one of two expression values:
GPC evaluates condition first. A nonzero condition selects value_if_true; zero selects value_if_false.
Important: only the selected branch is evaluated. If the condition is true, GPC evaluates value_if_true and does not evaluate value_if_false. If the condition is false, it evaluates value_if_false and does not evaluate value_if_true.
Choose a value
This is the expression form of a small if / else choice. The same logic written longhand is:
The unused branch does not run
Short-circuit branch evaluation makes guarded expressions safe:
The rule also applies to function calls and other side effects:
When use_a is true, only make_a() runs. When it is false, only make_b() runs. Parenthesize nested conditional expressions and keep side effects obvious so the code remains easy to review.
Assignment
Assignment stores the right-hand result in the writable variable or array element on the left. = means "gets the value," not "is equal to." Use == for comparison.
Compound assignment reads the current left-hand value, applies an operation, and writes the result back:
a = b
—
Assign b to a
a += b
a = a + b
Add and assign
a -= b
a = a - b
Subtract and assign
a *= b
a = a * b
Multiply and assign
a /= b
a = a / b
Divide and assign
a %= b
a = a % b
Remainder and assign
a &= b
a = a & b
Bitwise AND and assign
a |= b
a = a | b
Bitwise OR and assign
a ^= b
a = a ^ b
Bitwise XOR and assign
a <<= b
a = a << b
Shift left and assign
a >>= b
a = a >> b
Shift right and assign
a &&= b
a = a && b
Logical AND and assign
a ||= b
a = a || b
Logical OR and assign
a ^^= b
a = a ^^ b
Logical XOR and assign
Assignment associates from right to left, so a = b = 5; assigns 5 to b and then assigns that result to a. Prefer one assignment per line when the chained form would hide intent.
Parenthesize mixed bitwise/comparison expressions:
Without parentheses, equality binds more tightly than bitwise AND.
See the exact precedence table in the language reference.
Last updated

