A handle to externally manipulate items. A handle may refer to itself, but it may also refer to others, or to nothing.

Hierarchy

  • ItemHandle

Properties

id: string

The string representation of the ID that uniquely identifies an item within the space. ItemHandles sharing an identical id will all refer to the same object.

type: "item"

Returns string "item". This value can be used to distinguish ItemHandle and PlayerHandle.

Methods

  • Adds an impulsive force to the item's center of gravity. This is ignored if the item is immune to force. To apply impulsive force to points other than the center of gravity, use addImpulsiveForceAt.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Flow Control

    When APIs for Modifying the State of Other Items and Players, including this API, are called excessively frequently beyond the limit within a space, the results may be applied with significant delays. For more details, please refer to Flow Control.

    Parameters

    • force: Vector3

      Impulsive force (global coordinates)

    Returns void

  • Adds an impulsive force to a specified position on the item. This is ignored if the item is immune to force. There is no need for a PhysicalShape nor a mesh to be present on the point to apply the force.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Flow Control

    When APIs for Modifying the State of Other Items and Players, including this API, are called excessively frequently beyond the limit within a space, the results may be applied with significant delays. For more details, please refer to Flow Control.

    Parameters

    • impulse: Vector3

      Impulsive force (global coordinates)

    • position: Vector3

      Point to apply impulsive force (global coordinates)

    Returns void

  • Adds an impulsive torque to the item's center of gravity. This is ignored if the item is immune to force.

    Rate limitations

    An item can manipulate other handles up to 10 times per second. This can be exceeded momentarily, but please keep the average below this limit. If the limit is exceeded, a ClusterScriptError (rateLimitExceeded) error will occur and the operation will fail.

    Flow Control

    When APIs for Modifying the State of Other Items and Players, including this API, are called excessively frequently beyond the limit within a space, the results may be applied with significant delays. For more details, please refer to Flow Control.

    Parameters

    • torque: Vector3

      Impulsive torque (global coordinates)

    Returns void

  • Beta

    If the item exists, returns true. Note that this may return true even if it is currently loading.

    Returns boolean

  • Sends a message to an item. The item at the receiving end is expected to run a callback set using ClusterScript.onReceive.

    Messages sent to destroyed items or invalid ItemHandles will be ignored.

    For data types that can be used as the message's payload (the arg argument), refer to Sendable.

    If a non-Sendable value, such as undefined, is passed to arg argument as the message's payload, it will be ignored. This behaviour may change in future releases.

    Example

    The below example sends a message that corresponds to the example code on ClusterScript.onReceive.

    itemHandle.send("damage", 20);
    itemHandle.send("heal", 10);

    The below example sends a message with the message type chase, containing the handle of the player who used the item, to all items within a 2 meter radius.

    $.onUse((isDown, player) => {
    if (!isDown) return;
    let items = $.getItemsNear($.getPosition(), 2);
    for (let item of items) {
    item.send("chase", player);
    }
    });

    The actions an item should do upon receiving a message should be written in that item's ClusterScript.onReceive. In the below example, the item will chase the player for 5 seconds.

    $.onReceive((messageType, arg, sender) => {
    switch (messageType) {
    case "chase":
    $.state.target = arg;
    $.state.time = 0;
    break;
    }
    });

    $.onUpdate(deltaTime => {
    let target = $.state.target;
    if (!target) return;

    let time = $.state.time ?? 0;
    time += deltaTime;
    $.state.time = time;

    if (time > 5) {
    $.state.target = null;
    return;
    }

    $.setPosition($.getPosition().lerp(target.getPosition(), 0.02));
    });

    Rate limitations

    There is a limit on how often send can be called.

    • If the item running this script is a craft item, it must not exceed 10 calls per second per item
    • If the item running this script is a world item, the total number of calls to send, send, and sendTo from all world items in the space must not exceed 3000 calls per second

    It is possible to momentarily exceed this limit, but please ensure the average number of calls stays below this limit. If the limit is exceeded, ClusterScriptError (rateLimitExceeded) occurs and the operation fails.

    Flow Control

    When APIs for Modifying the State of Other Items and Players, including this API, are called excessively frequently beyond the limit within a space, the results may be applied with significant delays. For more details, please refer to Flow Control.

    Limitations from Flow Control

    If the item running this script is a world item, the send operation will only succeed if Flow Control Delay is 30 seconds or less. If the limit is exceeded, ClusterScriptError (rateLimitExceeded) occurs and the operation fails.

    Size limitations

    Encoded size of arg must be 1000 byte or less. If the data size exceeds the limit, a warning will be displayed. The data size can be calculated with computeSendableSize.

    If the data size significantly exceeds the limit, ClusterScriptError (requestSizeLimitExceeded) will occur and the send will fail.

    Parameters

    • messageType: string

      A short string to describe the message type

    • arg: Sendable

      The message payload

    Returns void

Generated using TypeDoc