Formulas Complex - magemonkeystudio/fabled GitHub Wiki
Complex Formulas — Constants, Operators, and Functions
This page lists the constants, operators, and functions available when writing value formulas. Use the {key} syntax to insert other values (for example, {health} or {baseValue}).
Constants
pi— π (approximately 3.14159265)e— Euler's number (approximately 2.71828)
Operators
| Operator | Description |
|---|---|
- |
Subtraction (also unary negation, e.g. -{key}) |
+ |
Addition |
* |
Multiplication |
/ |
Division |
^ |
Exponentiation (power) |
% |
Modulus (remainder), e.g. 11 % 2 → 1 |
Use parentheses () to control evaluation order. Operator precedence follows typical math rules (exponents, multiplication/division/modulus, addition/subtraction).
Functions
| Function | Description |
|---|---|
abs(x) |
Absolute value |
ceil(x) |
Round up to nearest integer |
floor(x) |
Round down to nearest integer |
round(x) |
Round to nearest integer |
sqrt(x) |
Square root |
sq(x) |
Square (x * x) |
sign(x) |
1 if x>0, -1 if x<0, 0 if x==0 |
sin(x) |
Sine — x in radians |
cos(x) |
Cosine — x in radians |
tan(x) |
Tangent — x in radians |
asin(x) |
Arc-sine — returns radians |
acos(x) |
Arc-cosine — returns radians |
atan(x) |
Arc-tangent — returns radians |
sinh(x) |
Hyperbolic sine |
cosh(x) |
Hyperbolic cosine |
tanh(x) |
Hyperbolic tangent |
min(x, y, ...) |
Minimum of the given numbers |
max(x, y, ...) |
Maximum of the given numbers |
sum(x, y, ...) |
Sum of the given numbers |
avg(x, y, ...) |
Average of the given numbers |
ln(x) |
Natural logarithm (base e) |
log(x) |
Base-10 logarithm |
random() |
Returns a pseudo-random number in the range [0, 1) |
Notes:
- Trigonometric functions use radians. Convert degrees to radians with
* pi / 180. - Use
sq(x)or the exponentx ^ 2for squares; cubes arex ^ 3. random()returns a pseudo-random float between 0 (inclusive) and 1 (exclusive).
Examples
- Average of two values:
( {a} + {b} ) / 2 - Clamp a value between 0 and a max:
max(0, min({value}, {max})) - Weighted value:
({base} * 0.7 + {bonus} * 0.3) - Convert degrees to radians for trig:
sin({angle} * pi / 180) - Conditional-like (using sign):
max(0, sign({damage}) * {damage})— ensures damage is non-negative