The Set Variable action allows you to compute a mathematical equation and store the result in a variable. The supported math syntax and functions are documented below.

Operators

Story Machine supports most common math operators: + - / * ( )
It also supports a few more technical operators:

  • % - modulus, the remainder
  • ^ - power

Example:

3 + (5 * 2^4) - (27 / 10)

Math functions and constants

Story Machine supports the following math functions. These are in the form of name(value).

  • abs - absolute value
  • acos - arccosine
  • asin - arcsine
  • atan - arctangent
  • atan2(y,x) - computes the angle between the x axis and a line from the origin passing through (x, y)
  • ceil - round up to the nearest whole number
  • cos - cosine
  • cosh - hyperbolic cosine
  • exp - exponential value (e ^ x)
  • fac - factorial
  • floor - round down to the nearest whole number
  • ln - natural log
  • log - base 10 log
  • ncr - combination (n, r)
  • npr - permutation (n, r)
  • pow - power (x ^ y)
  • sign - sign, 1 or -1
  • sin - sine
  • sinh - hyperbolic sine
  • sqrt - square root
  • tan - tangent
  • tanh - hyperbolic tangent

Story Machine also provides the following math constants, which can be used in equations.

  • e - Euler’s number
  • pi - Pi
  • deg2rad - multiply with an angle in degrees to get radians
  • rad2deg - multiply with an angle in radians to get degrees
  • random - a random number between 0 and 1

Logical functions

  • approach(value, target, change) - moves value towards target at rate change. Will not surpass target.
  • clamp(value, min, max) - clamps value to the min…max range
  • loop(value, min, max) - loops the value along the min…max range (e.g. loop(1.2, 0, 1) = 0.2.
  • min(a, b) - returns a or b, whichever is smaller
  • max(a, b) - returns a or b, whichever is larger

Variables

You can use variables in place of any value in Story Machine. Variables may have spaces in their names, and are not case-sensitive. Note however that variable names must be unique, and spaces/case are not differentiating. Therefore “my Value X” is the same variable name as “myvaluex”.