# Functions

<table data-full-width="true"><thead><tr><th>Returns</th><th width="237.0625">Syntax</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>A random number</td><td><mark style="color:blue;"><code>RAND()</code></mark><br><br><br>no parameters</td><td>Generates a random number</td><td><mark style="color:blue;"><code>RAND</code></mark><code>()</code> will output a random value between 0 and 1, e.g. <code>0.625</code><br><br><br><mark style="color:blue;"><code>RAND</code></mark><code>()*10</code> will output a random value between 0 and 10, e.g. <code>6.25</code></td></tr><tr><td>Rounded number</td><td><mark style="color:blue;"><code>ROUND</code></mark><code>(value, digits)</code><br><br>value (Number): the number to be rounded.<br><br>digits (Integer): the number of decimal places to round to.<br></td><td>Rounds a number to the specified number of decimal places</td><td>Example: <mark style="color:blue;"><code>ROUND</code></mark><code>(3.14159, 2)</code> → <code>3.14</code></td></tr><tr><td>Number of characters in the string, including spaces</td><td><mark style="color:blue;"><code>LEN</code></mark><code>("value")</code><br><br>value (String): the input string whose length is to be determined<br></td><td>Returns the length of a string</td><td><mark style="color:blue;"><code>LEN</code></mark><code>("hello")</code> will output a value of <code>5</code></td></tr><tr><td>Either <code>trueValue</code> or <code>falseValue</code>depending on the condition</td><td><mark style="color:blue;"><code>IF</code></mark><code>(condition,trueValue,falseValue)</code><br><br>condition (Expression): A logical expression that evaluates to true or false<br><br>trueValue (Any): The value returned if the condition is true<br><br>falseValue (Any): The value returned if the condition is false<br></td><td>Returns one value if a condition is true and another value if it is false</td><td><mark style="color:blue;"><code>IF</code></mark><code> (</code><mark style="color:purple;"><code>temperature</code></mark> <mark style="color:green;"><code>&#x3C;</code></mark><code> 10, “cold”, “hot")</code><br><br>if<br><mark style="color:purple;"><code>temperature</code></mark> <mark style="color:green;"><code>=</code></mark><code> 5</code> , the result is "cold", but if <mark style="color:purple;"><code>temperature</code></mark> <mark style="color:green;"><code>=</code></mark><code> 15</code> , the result is "hot".</td></tr><tr><td>Result of the evaluated expression</td><td><mark style="color:blue;"><code>EVAL</code></mark><code> (expression)</code></td><td>Re-evaluates a string as an expression and returns the result.<br><br>expression (String): a valid expression in string format to be evaluated.<br></td><td><mark style="color:blue;"><code>EVAL</code></mark><code>(”5 </code><mark style="color:green;"><code>+</code></mark><code> 5”) </code><mark style="color:green;"><code>=</code></mark><code> 10</code></td></tr><tr><td>Numeric value represented by the string, or an error if the conversion is not possible</td><td><mark style="color:blue;"><code>TO_NUMBER</code></mark><code>(value)</code></td><td>Converts a string to its numerical representation, if possible.</td><td><mark style="color:blue;"><code>TO_NUMBER</code></mark>(”5”) returns the number representation of the string, in this case 5, if possible.<br><br>If the input is not a valid number (e.g., "abc"), it returns an error.<br></td></tr><tr><td>Time passed between frames as a floating-point number, typically measured in seconds</td><td><mark style="color:blue;"><code>DELTA_TIME</code></mark></td><td>Retrieves the time elapsed between the current frame and the previous frame.<br><br>Commonly used in “on update” interactions to ensure smooth and consistent motion or timing.<br></td><td>If <mark style="color:blue;"><code>DELTA_TIME</code></mark> returns <code>0.016</code> (16 milliseconds), it can be used for animations or movement calculations: <code>position += speed * DELTA_TIME</code></td></tr><tr><td>Value from the target range that corresponds to the key in the lookup range</td><td><mark style="color:blue;"><code>XLOOKUP</code></mark><code>(dataset, key, lookupRange, targetRange)</code><br><br><br><code>dataset (Array)</code> the dataset containing the lookup and target ranges.<br><br><br><code>key (Any)</code> the value to search for in the lookup range.<br><br><br><code>lookupRange (Array)</code> the range where the key will be searched.<br><br><br><code>targetRange (Array)</code> the range from which the corresponding value will be returned.</td><td>Searches for a key in a lookup range and returns the corresponding value from a target range.</td><td><mark style="color:blue;"><code>XLOOKUP</code></mark>(salesData, "Product A", salesData["Products"], salesData["Revenue"]) → Returns the revenue associated with "Product A"</td></tr><tr><td>Value of the specified property from the target entity, which could include objects, settings, or other accessible data types</td><td><mark style="color:blue;"><code>GET</code></mark><code>(target, propertyName)</code></td><td>Retrieves the value of a specified property from a target entity. This can be used to access various attributes, settings, or metadata across different types of objects or entities.</td><td><mark style="color:blue;"><code>GET</code></mark><code>(</code><mark style="color:blue;"><code>OBJ</code></mark><code>("Box"), "position")</code> → Retrieves the position of the object named "Box”</td></tr><tr><td>Reference to the specified object, which can then be used in other functions or operations</td><td><mark style="color:blue;"><code>OBJ</code></mark><code>(name)</code><br><br>name (String)<br>the name of the object to retrieve</td><td>Retrieves a reference to an object by its name. This is used to interact with specific objects.</td><td><mark style="color:blue;"><code>OBJ</code></mark>("Box") → Retrieves the object named "Box" for further interaction</td></tr><tr><td></td><td><mark style="color:blue;"><code>UI</code></mark></td><td>Same as above</td><td></td></tr><tr><td></td><td><mark style="color:blue;"><code>VAR</code></mark></td><td>Same as above</td><td></td></tr><tr><td></td><td><mark style="color:blue;"><code>PARENT_OF</code></mark></td><td>Same as above</td><td></td></tr><tr><td></td><td><mark style="color:blue;"><code>CHILDREN_OF</code></mark></td><td>Same as above</td><td></td></tr><tr><td>Contextual reference to the current object, component, or environment</td><td><mark style="color:blue;"><code>SELF</code></mark></td><td></td><td></td></tr><tr><td>In an interaction, returns the trigger</td><td><mark style="color:blue;"><code>TRIGGER</code></mark></td><td>In an interaction, returns the trigger or event that initiated the action.</td><td>Interaction: trigger ”on click”, action “set variable” → TRIGGER()<br>will return the object name clicked<br></td></tr><tr><td>Scalar value representing the dot product of the two vectors. A positive result indicates alignment, zero indicates perpendicularity, and a negative result indicates opposing directions</td><td><mark style="color:blue;"><code>DOT</code></mark><code>(v1, v2)</code><br><br><br><code>v1 (Vector)</code> the first input vector<br><br><code>v2 (Vector)</code> the second input vector</td><td>Calculates the dot product of two vectors. The dot product is a scalar value that represents the magnitude of one vector projected onto another.</td><td><mark style="color:blue;"><code>DOT</code></mark><code>([1, 0, 0], [0, 1, 0])</code> → 0 (vectors are perpendicular)</td></tr><tr><td>Vector that is perpendicular to both input vectors</td><td><mark style="color:blue;"><code>CROSS</code></mark><code>(v1, v2)</code></td><td>Calculates the cross product of two vectors. The cross product results in a new vector that is perpendicular to both input vectors and represents the area of the parallelogram formed by the vectors.</td><td><mark style="color:blue;"><code>CROSS</code></mark><code>([1, 0, 0], [0, 1, 0]) → [0, 0, 1]</code> a vector perpendicular to both input vectors</td></tr><tr><td>Scalar value representing the length of the vector</td><td><mark style="color:blue;"><code>MAGNITUDE</code></mark><code>(vector)</code></td><td>Calculates the magnitude (length) of a vector. The magnitude represents the distance of the vector from the origin in space.</td><td><mark style="color:blue;"><code>MAGNITUDE</code></mark><code>([3, 4, 0])</code> → 5 (calculated as √(3² + 4² + 0²))</td></tr><tr><td>Unit vector with the same direction as the input vector but a magnitude of 1</td><td><mark style="color:blue;"><code>NORMALIZE</code></mark><code>(vector)</code></td><td>Converts a vector into a unit vector (a vector with a magnitude of 1) while maintaining its direction.</td><td><mark style="color:blue;"><code>NORMALIZE</code></mark><code>([3, 4, 0])</code> → [0.6, 0.8, 0] (calculated by dividing each component by the magnitude, √(3² + 4² + 0²) = 5).</td></tr><tr><td>A value or vector between <code>v1</code> and v2 based on the interpolation factor <code>factor</code></td><td><mark style="color:blue;"><code>LERP</code></mark><code>(v1, v2, factor)</code><br><br><br><code>v1 (Number or Vector)</code> the starting value or vector of the interpolation<br><br><br><code>v2 (Number or Vector)</code> the ending value or vector of the interpolation<br><br><br><code>factor (Number)</code> the interpolation factor, a value between 0 and 1, where 0 represents <code>v1</code> and 1 represents <code>v2</code></td><td>Performs linear interpolation between two values or vectors based on a given ratio.</td><td><mark style="color:blue;"><code>LERP</code></mark><code>([0, 0], [10, 10], 0.5)</code> → [5, 5] (halfway between the two vectors)</td></tr></tbody></table>
