UTILS

Utility functions for strings, colors, and distance calculations.

Availability: Client & Server

Methods


UTILS.anglDst

client server

Calculate the shortest angular distance between two angles

Signature: num action(num, num)

Parameters:

NameTypeDescription
xnumFirst angle in radians
ynumSecond 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:

NameTypeDescription
txtstrText 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:

NameTypeDescription
xnumStarting X coordinate
ynumStarting Y coordinate
x2numTarget X coordinate
y2numTarget 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:

NameTypeDescription
xnumStarting X coordinate
ynumStarting Y coordinate
znumStarting Z coordinate
x2numTarget X coordinate
y2numTarget Y coordinate
z2numTarget 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:

NameTypeDescription
x1numFirst X coordinate
y1numFirst Y coordinate
x2numSecond X coordinate
y2numSecond 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:

NameTypeDescription
x1numFirst X coordinate
y1numFirst Y coordinate
z1numFirst Z coordinate
x2numSecond X coordinate
y2numSecond Y coordinate
z2numSecond 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:

NameTypeDescription
numnumHue 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:

NameTypeDescription
strstrHex 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:

NameTypeDescription
strstrHex 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:

NameTypeDescription
minnumMinimum value
maxnumMaximum 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:

NameTypeDescription
minnumMinimum value
maxnumMaximum 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:

NameTypeDescription
txtstrOriginal text
segmstrSubstring to find
witstrReplacement 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:

NameTypeDescription
rnumRed component (0-255)
gnumGreen component (0-255)
bnumBlue 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:

NameTypeDescription
txtstrText to search in
searchstrSubstring 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:

NameTypeDescription
strstrString 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:

NameTypeDescription
strstrString 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:

NameTypeDescription
strstrString to truncate
lnnumMaximum length
noDotboolIf true, don't add ellipsis
startnumStarting index for truncation

Returns: str - Truncated string

str result = GAME.UTILS.truncateTxt("value", 0, true, 0);