EXPRESSION OPERATORS
In HookScript, you can use several operators for performing calculations on your expressions. The allowed operators are dependent on your data type, with the following operators currently supported.
Comments
//: two forward slashes allow you to comment out your text, so the evaluator will ignore any text that comes after two forward slashes on that line
Prefix Operators
!(negation): allows you to negate the value of a boolean expressions (e.g., !true == false)-(reverse): syntatic sugar for multiplying anintorfloatby -1
Postfix Operators
++(increment): syntactic sugar for adding 1 to anintorfloat--(decrement): syntactic sugar for subtracting 1 from anintorfloat
Arithmetic Operators
+(addition): allows you to add twointorfloattypes, or concatenatetexttypes-(subtraction): allows you to substract twointorfloattypes*(multiplication): allows you to multiply twointorfloattypes/(division): allows you to divide twointorfloattypes%(modulo): allows you to return the remainder when dividinginttypes
Shorthand Assignment Operators
+=(add): allows you to add value to a variable-=(subtract): allows you to subtract a value from a variable*=(multiply): allows you to multiply a variable by the value/=(divide): allows you to divide a variable by the value
Comparison Operators
==(equals): allows you to compare twoint,float,bool, ortexttypes!=(equals): allows you to compare twoint,float,bool, ortexttypes>(greater than): allows you to compare twoint,float, ortexttypes<(less than): allows you to compare twoint,float, ortexttypes<=(less than or equal to): allows you to compare twoint,float, ortexttypes>=(greater than or equal to): allows you to compare twoint,float, ortexttypesin(in): returnstrueorfalseif alist,dict,record, ortextcontains the value, key, or subtext
Built-in Functions
len(object): returns anintthat is the number of characters in atextvalue, the number of elements in anarrayvalue, or the number of elements in amapvalueprint(...objects): prints the provided object(s) to the console; returns the number of bytes written to the consoletypeof(object): returns the underlying type of an object as textsource(path): pulls data into HookScript for processing
Examples:
10 > 8 // returns true
10 < 8 // returns false
10 >= 10 // returns true
10 <= 9 // returns false
10 + 2 // returns 12
10 - 2 // returns 8
10 / 5 // returns 2
10 * 5 // returns 50
"hello" + " world" // returns "hello world"
len("hello world") // returns 11
len(["a", "b", "c"]) // returns 3
!true // returns false
-(10 * 2) // returns -20
print("hello") // prints "text" to the console
print(typeof("hello")) // prints "text" to the console
print("ll" in "hello") // returns true
print(40 in [10, 20, 30]) // returns false
print("name" in { name: "PJ", age: 7 }) // returns true
Loading Playground