Uuid

Available in: Interface Scripts Client Entity Scripts Server Entity Scripts Assignment Client Scripts

A UUID (Universally Unique IDentifier) is used to uniquely identify entities, overlays, avatars, and the like. It is represented in JavaScript as a string in the format, {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}, where the "n"s are hexadecimal digits.
Methods

Properties:
Name Type Description
NULL Uuid The null UUID, {00000000-0000-0000-0000-000000000000}.

Methods

fromString(string) → {Uuid}
Generates a UUID from a string representation of the UUID.
Parameters:
Name Type Description
string string A string representation of a UUID. The curly braces are optional.
Returns:
A UUID if the given string is valid, null otherwise.
Type: Uuid
Example

Valid and invalid parameters.

var uuid = Uuid.fromString("{527c27ea-6d7b-4b47-9ae2-b3051d50d2cd}");
print(uuid); // {527c27ea-6d7b-4b47-9ae2-b3051d50d2cd}

uuid = Uuid.fromString("527c27ea-6d7b-4b47-9ae2-b3051d50d2cd");
print(uuid); // {527c27ea-6d7b-4b47-9ae2-b3051d50d2cd}

uuid = Uuid.fromString("527c27ea");
print(uuid); // null
generate() → {Uuid}
Generate a new UUID.
Returns:
A new UUID.
Type: Uuid
Example

Generate a new UUID and reports its JavaScript type.

var uuid = Uuid.generate();
print(uuid);        // {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
print(typeof uuid); // string
isEqual(idA, idB) → {boolean}
Test whether two given UUIDs are equal.
Parameters:
Name Type Description
idA Uuid The first UUID to compare.
idB Uuid The second UUID to compare.
Returns:
true if the two UUIDs are equal, otherwise false.
Type: boolean
Example

Demonstrate true and false cases.

var uuidA = Uuid.generate();
var uuidB = Uuid.generate();
print(Uuid.isEqual(uuidA, uuidB)); // false
uuidB = uuidA;
print(Uuid.isEqual(uuidA, uuidB)); // true
isNull(id) → {boolean}
Test whether a given UUID is null.
Parameters:
Name Type Description
id Uuid The UUID to test.
Returns:
true if the UUID equals Uuid.NULL or is null, otherwise false.
Type: boolean
Example

Demonstrate true and false cases.

var uuid; // undefined
print(Uuid.isNull(uuid)); // false
uuid = Uuid.generate();
print(Uuid.isNull(uuid)); // false
uuid = Uuid.NULL;
print(Uuid.isNull(uuid)); // true
uuid = null;
print(Uuid.isNull(uuid)); // true
print(label, id)
Print to the program log a text label followed by the UUID value.
Parameters:
Name Type Description
label string The label to print.
id Uuid The UUID to print.
Example

Two ways of printing a label plus UUID.

var uuid = Uuid.generate();
Uuid.print("Generated UUID:", uuid); // Generated UUID: {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
print("Generated UUID: " + uuid);    // Generated UUID: {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
   
toString(id) → {string}
Generates a string representation of a UUID. However, because UUIDs are represented in JavaScript as strings, this is in effect a no-op.
Parameters:
Name Type Description
id Uuid The UUID to generate a string from.
Returns:
- A string representation of the UUID.
Type: string