HomeWeb Components API Reference - v0.10.1
    Preparing search index...

    Class ScriptElement

    The ScriptElement interface provides properties and methods for manipulating <pc-script> elements. The ScriptElement interface also inherits the properties and methods of the AsyncElement interface.

    Script attributes can be supplied through two channels:

    • Per-property attributes: any non-reserved attribute on the element maps to the script attribute of the same name (kebab-case to camelCase, e.g. focus-pointfocusPoint). Values are parsed according to the type of the attribute's current value — initially the script's declared default (numbers, booleans, strings, Vec2/3/4, Color, Quat as Euler angles) — and the asset:/entity:/vec2:/vec3:/vec4:/color: prefixes may be used to be explicit.
    • The attributes JSON attribute: an object supporting nested structures and attribute names that collide with reserved HTML attribute names (e.g. title).

    When both specify the same attribute, the per-property attribute wins — at creation and whenever either channel changes at runtime. The element's own name and enabled attributes configure the element itself and are not script attributes.

    Changing name on a live element destroys the old-name script instance and creates the new-name one, re-applying both attribute channels to it.

    The element becomes ready once its script instance has been created by the parent <pc-scripts> element.

    scriptattributeschange - Fired when the script's attributes change. The detail carries the new attributes object. Bubbles.

    scriptenablechange - Fired when the script's enabled state changes. The detail carries the new enabled state. Bubbles.

    scriptnamechange - Fired when the script is renamed on a live element. The detail carries oldName and newName. Bubbles.

    Hierarchy (View Summary)

    Index
    • get closestApp(): AppElement | null

      The nearest ancestor <pc-app> element, or null if this element has no <pc-app> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns AppElement | null

      The closest app element, or null.

    • get closestEntity(): EntityElement | null

      The nearest ancestor <pc-entity> element, or null if this element has no <pc-entity> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns EntityElement | null

      The closest entity element, or null.

    • get enabled(): boolean

      Gets the enabled state of the script.

      Returns boolean

      The enabled state of the script.

    • set enabled(value: boolean): void

      Sets the enabled state of the script.

      Parameters

      • value: boolean

        The enabled state of the script.

      Returns void

    • get name(): string

      Gets the name of the script.

      Returns string

      The name.

    • set name(value: string): void

      Sets the name of the script to create. The name attribute is the single source of truth (it is what the parent <pc-scripts> element reads when creating the instance), so the property writes through to it — assigning before insertion works as expected:

      const script = document.createElement('pc-script');
      script.name = 'rotate';
      scriptsElement.appendChild(script);
      await script.ready();

      Parameters

      • value: string

        The name.

      Returns void

    • get script(): Script | null

      Gets the Script instance created for this element. Returns null until the instance exists — await whenReady or the element's ready() promise before accessing it.

      Returns Script | null

      The script instance, or null.

    • get scriptAttributes(): Record<string, any>

      Gets the attributes of the script.

      Returns Record<string, any>

      The attributes of the script.

    • set scriptAttributes(value: Record<string, any>): void

      Sets the attributes of the script as an object. Values are converted with the same rules as the attributes attribute: asset:/entity: references and vec2:/vec3:/vec4:/ color: prefixed strings are resolved, and a plain numeric array is converted to the type of the attribute it targets when that attribute currently holds a Vec2, Vec3, Vec4 or Color.

      Parameters

      • value: Record<string, any>

        The attributes of the script.

      Returns void

    • Called when the element is fully initialized and ready. Subclasses should call this when they're ready. Resolves the ready promise and dispatches a bubbling, composed ready event.

      Returns void