Thyme is the scripting language built into Phun. It was created by Emil, and is used to load scenes and change certain variables like gravity. Thyme can be found in the config files (.cfg), the phun files (.phn) and in the Phun Console.
Thyme is a staticly typed imperative language. Phun uses = for assignment, so to set the number of undo levels to 5 one can type App.maxUndo = 5; in the console or config.cfg.
There are five basic types in Phun:
- Boolean — true or false
- Integer — -1, 0, +1, 2, ...
- Float — 0.32, -1.0e10, +Inf, -Inf, ...
- String — "This is a string"
- List — ["A", "list", "of", "strings"], [1,2,3,4], [1.0, 2.0, 0.0, Inf]
Lists must be homogeneous, meaning that each element is of the same type (either all String, all Float etc).
To see some usage of Thyme, see autoexec.cfg.
There are quite a few variables and functions built into Phun, and these are ordered into the following groups:
To show the value of any variable in Phun, just type the name of that variable in the console. As an example, typing "App.waterColor" in the console would print out something like [0.1, 0.1, 1.0, 0.7]. Here, like with most colors, the four components of the float list represents red, green, blue and alpha (opacity) respectively.
Some Math. and Math.comp. operations can be used with specific syntax:
- Conditions —
x ? y : z (x = condition, y = if true, z = if false)
- Equal —
x == y
- Not equal —
x != y
- Greater than —
x > y
- Greater than or equal —
x >= y
- Less than —
x < y
- Less than or equal —
x <= y
- Addition —
x + y
- Subtraction —
x - y
- Multiplication —
x * y
- Division —
x / y
- Modulus —
x % y
- Power of —
x ^ y
- Negate —
-x
- Boolean NOT —
!x
- Boolean AND —
x && y
- Boolean OR —
x || y
- List addition —
x ++ y
Examples:
{ Scene.my.var1 >= 9 ? {Scene.my.var1 = 0} : {Scene.my.var1 = Scene.my.var1 + 1} };
Useful math functions:
min = (a, b) => { a < b ? a : b };
max = (a, b) => { a > b ? a : b };
is_between = (a, min, max) => { a >= min && a <= max };
saturate = (a, min, max) => { a < min ? min : a > max ? max : a };
abs = (x) => { x >= 0 ? x : -x };
sqrt = (x) => { x ^ 0.5 };
distance1D = (a, b) => { a > b ? a - b : b - a };
distance2D = (pa, pb) => { ((pa(0) - pb(0)) ^ 2 + (pa(1) - pb(1)) ^ 2) ^ 0.5 };
distance3D = (pa, pb) => { ((pa(0) - pb(0)) ^ 2 + (pa(1) - pb(1)) ^ 2 + (pa(2) - pb(2)) ^ 2) ^ 0.5 };
floor = (x) => { x % 1 == 0 ? x : x >= 0 ? x - (x % 1) : x - (x % 1) - 1 };
round = (x) => { x >= 0 ? x + 0.5 - ((x + 0.5) % 1) : x - 0.5 - ((x - 0.5) % 1) };
ceil = (x) => { x % 1 == 0 ? x : x >= 0 ? x - (x % 1) + 1 : x - (x % 1) };
Last modified May 22, 2011 1:12 am