簡易運算式

在 TJAction 中,你可以編寫一些簡易的運算式來補助計算、供插件本身功能取值。

符號定義

  • 基礎運算 + - * / % (取餘運算)

  • 資料比對 =, !=, >, <, >=, <=

  • 變數設定 a := 100

  • 次方 10**100

  • 階乘 10!

  • 邏輯運算 a and b, a or b, !a

  • 布林 true/false

  • 字串 'hello world'

  • 數字 1234

  • 函數呼叫 func(1,2,3)

  • 角度 30deg

特殊定義

  • 字串可乘以數字 'hello' * 3 ⇒ 'hellohellohello'

  • 字串 % 字串 ⇒ 忽略大小寫比對 'hello' % 'Hello' ⇒ true

  • 字串 > 字串 ⇒ 左邊是否以右邊開頭 'hello world' > 'hello' ⇒ true

  • 字串 < 字串 ⇒ 左邊是否以右邊結尾 'hello world' < 'world' ⇒ true

基本函數

  • not(bool) 取反 not(1=1) ⇒ false

  • cos(rad) 餘弦 cos(90deg) ⇒ 0

  • sin(rad) 正弦 sin(90deg) ⇒ 1

  • rad(deg) 弧度轉弳度 rad(30) ⇒ 0.5235987756 (等同 30deg)

  • deg(rad) 弳度轉弧度 deg(0.5235987756) ⇒ 30.0000000001 (多的是誤差)

  • abs(number) 取絕對值 abs(-1.5) ⇒ 1.5

  • sum(a, b, ...) 將所有數值加總 sum(1, 2, 3.5) ⇒ 6.5

  • avg(a, b, ...) 平均值(若沒有參數,結果為 0) avg(2, 4, 6) ⇒ 4

  • max(a, b, ...) 找出最大值 max(1, 5, 3) ⇒ 5

  • min(a, b, ...) 找出最小值 min(1, 5, 3) ⇒ 1

  • clamp(x, min, max) 限制 x 的值不超出 [min, max] 範圍 clamp(10, 0, 5) ⇒ 5

  • sqrt(number) 平方根 sqrt(9) ⇒ 3

  • floor(number) 無條件捨去(向下取整) floor(2.9) ⇒ 2

  • ceil(number) 無條件進位(向上取整) ceil(2.1) ⇒ 3

  • round(number) 四捨五入 round(2.5) ⇒ 3

  • random() 隨機布林值 random() ⇒ true/false

  • random(probability) 以指定機率返回 true,否則 false random(0.25) ⇒ true/false (25% 機率為 true)

  • random(a, b) 回傳 a 到 b 間的隨機實數 random(1, 3) ⇒ 2.184

  • randomint(a, b) 回傳 a 到 b 間的隨機整數(含兩端) randomint(1, 3) ⇒ 2

Last updated