Simple Expressions

In TJAction, you can write some simple expressions to assist with calculations and provide values for plugin functions.

Symbol Definitions

  • Basic operations + - * / % (modulo)

  • Comparison =, !=, >, <, >=, <=

  • Variable assignment a := 100

  • Power 10**100

  • Factorial 10!

  • Logical operations a and b, a or b, !a

  • Boolean true/false

  • String 'hello world'

  • Number 1234

  • Function call func(1,2,3)

  • Angle 30deg

Special Definitions

  • String multiplied by number 'hello' * 3 ⇒ 'hellohellohello'

  • String % String ⇒ Case-insensitive comparison 'hello' % 'Hello' ⇒ true

  • String > String ⇒ Left starts with right 'hello world' > 'hello' ⇒ true

  • String < String ⇒ Left ends with right 'hello world' < 'world' ⇒ true

Basic Functions

  • not(bool) Logical NOT not(1=1) ⇒ false

  • cos(rad) Cosine cos(90deg) ⇒ 0

  • sin(rad) Sine sin(90deg) ⇒ 1

  • rad(deg) Convert degree to radian rad(30) ⇒ 0.5235987756 (same as 30deg)

  • deg(rad) Convert radian to degree deg(0.5235987756) ⇒ 30.0000000001 (minor error)

  • abs(number) Absolute value abs(-1.5) ⇒ 1.5

  • sum(a, b, ...) Sum of all numbers sum(1, 2, 3.5) ⇒ 6.5

  • avg(a, b, ...) Average (0 if no arguments) avg(2, 4, 6) ⇒ 4

  • max(a, b, ...) Maximum value max(1, 5, 3) ⇒ 5

  • min(a, b, ...) Minimum value min(1, 5, 3) ⇒ 1

  • clamp(x, min, max) Limit x within [min, max] clamp(10, 0, 5) ⇒ 5

  • sqrt(number) Square root sqrt(9) ⇒ 3

  • floor(number) Floor (round down) floor(2.9) ⇒ 2

  • ceil(number) Ceiling (round up) ceil(2.1) ⇒ 3

  • round(number) Round to nearest round(2.5) ⇒ 3

  • random() Random boolean random() ⇒ true/false

  • random(probability) Return true with given probability, else false random(0.25) ⇒ true/false (25% chance of true)

  • random(a, b) Return random real number between a and b random(1, 3) ⇒ 2.184

  • randomint(a, b) Return random integer between a and b (inclusive) randomint(1, 3) ⇒ 2

Last updated