UTILS
Utility functions for strings, colors, and distance calculations.
Availability: Client & Server
Methods
- anglDst
- copyToClipboard
- getDir2D
- getDir3D
- getDist2D
- getDist3D
- hexFromHue
- HEXtoRGB
- invertHex
- randFloat
- randInt
- replaceText
- RGBtoHEX
- textContains
- toLower
- toUpper
- truncateTxt
UTILS.anglDst
client server
Calculate the shortest angular distance between two angles
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | First angle in radians |
y | num | Second angle in radians |
Returns: num - The angular distance
num result = GAME.UTILS.anglDst(0, 10);
UTILS.copyToClipboard
client
Copy text to the system clipboard (client-side only)
Signature: action(str)
Parameters:
| Name | Type | Description |
|---|---|---|
txt | str | Text to copy |
GAME.UTILS.copyToClipboard("Hello");
UTILS.getDir2D
client server
Get the 2D direction angle from one point to another
Signature: num action(num, num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Starting X coordinate |
y | num | Starting Y coordinate |
x2 | num | Target X coordinate |
y2 | num | Target Y coordinate |
Returns: num - The direction angle in radians
num dir2D = GAME.UTILS.getDir2D(0, 10, 0, 10);
UTILS.getDir3D
client server
Get the 3D direction from one point to another
Signature: obj action(num, num, num, num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Starting X coordinate |
y | num | Starting Y coordinate |
z | num | Starting Z coordinate |
x2 | num | Target X coordinate |
y2 | num | Target Y coordinate |
z2 | num | Target Z coordinate |
Returns: obj - Object with x and y rotation angles
obj dir3D = GAME.UTILS.getDir3D(0, 10, 0, 0, 10, 0);
UTILS.getDist2D
client server
Calculate 2D distance between two points
Signature: num action(num, num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x1 | num | First X coordinate |
y1 | num | First Y coordinate |
x2 | num | Second X coordinate |
y2 | num | Second Y coordinate |
Returns: num - The distance between the points
num dist2D = GAME.UTILS.getDist2D(0, 10, 0, 10);
UTILS.getDist3D
client server
Calculate 3D distance between two points
Signature: num action(num, num, num, num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x1 | num | First X coordinate |
y1 | num | First Y coordinate |
z1 | num | First Z coordinate |
x2 | num | Second X coordinate |
y2 | num | Second Y coordinate |
z2 | num | Second Z coordinate |
Returns: num - The distance between the points
num dist3D = GAME.UTILS.getDist3D(0, 10, 0, 0, 10, 0);
UTILS.hexFromHue
client server
Convert a hue value to a hex color string
Signature: str action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
num | num | Hue value (0-360) |
Returns: str - Hex color string
str result = GAME.UTILS.hexFromHue(0);
UTILS.HEXtoRGB
client server
Convert a hex color string to RGB values
Signature: obj action(str)
Parameters:
| Name | Type | Description |
|---|---|---|
str | str | Hex color string |
Returns: obj - Object with r, g, b properties (0-255)
obj result = GAME.UTILS.HEXtoRGB("value");
UTILS.invertHex
client server
Invert a hex color to its complementary color
Signature: str action(str)
Parameters:
| Name | Type | Description |
|---|---|---|
str | str | Hex color string to invert |
Returns: str - Inverted hex color string
str result = GAME.UTILS.invertHex("value");
UTILS.randFloat
client server
Generate a random float between min and max
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
min | num | Minimum value |
max | num | Maximum value |
Returns: num - Random float
num result = GAME.UTILS.randFloat(0, 100);
UTILS.randInt
client server
Generate a random integer between min and max (inclusive)
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
min | num | Minimum value |
max | num | Maximum value |
Returns: num - Random integer
num result = GAME.UTILS.randInt(0, 100);
UTILS.replaceText
client server
Replace all occurrences of a substring
Signature: str action(str, str, str)
Parameters:
| Name | Type | Description |
|---|---|---|
txt | str | Original text |
segm | str | Substring to find |
wit | str | Replacement string |
Returns: str - Text with replacements
str result = GAME.UTILS.replaceText("Hello", "value", "value");
UTILS.RGBtoHEX
client server
Convert RGB values to a hex color string
Signature: str action(num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
r | num | Red component (0-255) |
g | num | Green component (0-255) |
b | num | Blue component (0-255) |
Returns: str - Hex color string
str result = GAME.UTILS.RGBtoHEX(255, 128, 0);
UTILS.textContains
client server
Check if text contains a substring
Signature: bool action(str, str)
Parameters:
| Name | Type | Description |
|---|---|---|
txt | str | Text to search in |
search | str | Substring to find |
Returns: bool - True if substring is found
bool result = GAME.UTILS.textContains("Hello", "value");
UTILS.toLower
client server
Convert a string to lowercase
Signature: str action(str)
Parameters:
| Name | Type | Description |
|---|---|---|
str | str | String to convert |
Returns: str - Lowercase string
str result = GAME.UTILS.toLower("value");
UTILS.toUpper
client server
Convert a string to uppercase
Signature: str action(str)
Parameters:
| Name | Type | Description |
|---|---|---|
str | str | String to convert |
Returns: str - Uppercase string
str result = GAME.UTILS.toUpper("value");
UTILS.truncateTxt
client server
Truncate text to a specified length
Signature: str action(str, num, bool, num)
Parameters:
| Name | Type | Description |
|---|---|---|
str | str | String to truncate |
ln | num | Maximum length |
noDot | bool | If true, don't add ellipsis |
start | num | Starting index for truncation |
Returns: str - Truncated string
str result = GAME.UTILS.truncateTxt("value", 0, true, 0);