Uuid

Description

A UUID (Universally Unique IDentifier) is used to uniquely identify entities, 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.

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

Properties

Name Type Summary
NULL Uuid The null UUID, {00000000-0000-0000-0000-000000000000}.

Methods

Name Return Value Summary
fromString Uuid Generates a UUID from a string representation of the UUID.
generate Uuid Generate a new UUID.
isEqual boolean Test whether two given UUIDs are equal.
isNull boolean Test whether a given UUID is null.
print None Print to the program log a text label followed by the UUID value.
toString string Generates a string representation of a UUID. However, because UUIDs are represented in JavaScript as strings, this is in effect a no-op.

Method Details

(static) fromString( string ) → {Uuid}
Returns: A UUID if the given string is valid, null otherwise.

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.
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
(static) generate( ) → {Uuid}
Returns: A new UUID.

Generate a new 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
(static) isEqual( idA, idB ) → {boolean}
Returns: true if the two UUIDs are equal, otherwise false.

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.
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
(static) isNull( id ) → {boolean}
Returns: true if the UUID equals Uuid.NULL or is null, otherwise false.

Test whether a given UUID is null.

Parameters

Name Type Description
id Uuid The UUID to test.
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
(static) 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}
     
(static) toString( id ) → {string}
Returns: - A string representation of the UUID.

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.