HomeIndex

Dinky Expressions

Expressions in Dinky are anything that returns a single value. They can be as simple as 2 or a+100 or more complex operations like a+((5/2)*10) and a ? 10 : 20.
Expressions can be assigned to variables or passed to functions.
local a = 67*6 setScore(hits*100)
Expressions perform what is called const folding. If you write 10+9 the compiler will emit 19. You can do complex math operations at run-time without fear of performance issues. If you do a+9*10 the compile will generate a+90.
+, -, *, /, %
Math operators
~, !
Unary operators
==, !=, <, >, <=, >=
Comparison operators
|, &
Bit-wise
&&, ||
Logical operators
if (foo && bar) { ... }
Logical comparisons perform what is called "short circuiting". If a == 0 and b == 1, doing if (a && b) will only compare a before skipping the rest of the comparison. This is important when doing if (funcA() && funcB()) and running funcA() and funcB() is time consuming.
+=, -=, *=, /=, |=, &=, ++, --
Assignment operators
local v = 10 v += 2 v -= 1 v++ v-- ++v --v
The ++ and -- operator can be applied before or after evaluating the variable. If you do
local v = 6 if (++v == 7) { ... } // true if (v++ == 7) { ... } // true if (v == 8) { ... } // true
a?b:c | a?:c
Trinary operators
If a is true, then b is returned, otherwise c.
local found = (name == "Delores" ? true : false)
Dinky also supports a special version that return a if a is true, otherwise c. This can be useful in cases like bigFunc() ?: 0. If bugFunc() is computationally expensive, you don't want to execute it twice.
actor = findActor(point(x,y))?:ransome