Skip to content

ComponentOperation

ComponentOperation APIs manage gameplay components and community components via your assembler scripts.

Functions

number/boolean/string/table getDataElementValue(number dataElement, dataElementType type, string key)

Returns the value of the data element
  • dataElement The data element
  • type The type of the data element
  • key The name of the data element

void updateModuleData(number dataElement, dataElementType type, string key, number/boolean/string/table value)

Updates the value of the data element
  • dataElement The data element
  • type The type of the data element
  • key The name of the data element
  • value The custom value

number getDataElement(number dataElement, string key, dataElementType type)

Returns the child data elements of a specific type
  • dataElement The data element
  • key The name of the data element
  • type The type of the data element

number getNode(number dataElement, string key)

Returns the child data elements of the LuaNode type
  • dataElement The data element
  • key The name of the data element

boolean containsNode(number dataElement, string key)

Returns true if the child data elements of the LuaNode type, or false if not.
  • dataElement The data element
  • key The name of the data element

number addChild(number dataElement)

Adds a child data element to the data element list and returns the data element added as a child
  • dataElement The data element list

void removeChild(number dataElement)

Deletes a child element from the data element list
  • dataElement The data element to remove as a child

number getChild(number dataElement, string key, number index )

Returns a data element child by index
  • dataElement The data element
  • key The name of the data element
  • index The index of the child data element to return

number addComponent(number YahahaObjectID, string identifier)

Adds a component to the YahahaObject using the component's identifier and returns the new Lua element
  • YahahaObjectIDThe unique identifier of the YahahaObject
  • identifier The identifier of the component

number getComponent(number YahahaObjectID, string identifier)

Returns a component on the YahahaObject using the component's identifier
  • YahahaObjectIDThe unique identifier of the YahahaObject
  • identifier The identifier of the component

boolean containsComponent(number YahahaObjectID, string identifier)

Returns true if the YahahaObject contains the built-in component, or false if not
  • YahahaObjectIDThe unique identifier of the YahahaObject
  • identifier The identifier of the built-in component

void enableComponent(number dataElement, boolean enable)

Enables or disables the component
  • dataElement The data element
  • enable If true, enables the component; if false, disenables the component

number fireClick(number dataElement)

Simulates a click on a data element button and returns the new Lua element
  • dataElement The data element

Code samples

-- Load the built-in assembler module in the header code 
require("assembler")
-- Execute the logic part
function execute()
    -- Create a YahahaObject using asset ID 274880352875 and name it as "testObject"
    local testObject = createAsset(274880352875)

    -- Add the gameplay component Move to the YahahaObject and store the data elements of the component in the "move" variable
    local move = addComponent(testObject, GameplayComponent.Move)

    -- Get the "setting" node of the move data element 
    local setting = getNode(move, "setting")

    -- Get the first "toPoint" child of the move data element by the specified index 0
    local start = getChild(setting, "toPoint", 0)

    -- Update the "stayTime" of the move data element to 1 seconds, and "moveTime" to 10 seconds
    updateLuaElementValue(start, LuaElementType.Time, "stayTime", 1)
    updateLuaElementValue(start, LuaElementType.Time, "moveTime", 10)

    -- Get the second "toPoint" child of the move data element by the specified index 1
    local relative = getChild(setting, "toPoint", 1)

    -- Get the stayTime and moveTime values and print them to the Console's output
    local stay_time = getLuaElementValue(relative, LuaElementType.Time, "stayTime")
    local move_speed = getLuaElementValue(relative, LuaElementType.Time, "moveTime")
    print(string.format("stay time = %d", stay_time))
    print(string.format("move speed = %d", move_speed))

    -- Get the "AddRelativePosition" button of the move data element 

    local button = getField(setting, "AddRelativePosition", LuaElementType.Button)

    -- Simulate a click on the "AddRelativePosition" button three times, and get the new points generated by the simulated click.
    for i = 1, 3 do
        local newPoint = fireClick(button)
        -- Update the position of these new points with a new set of coordinates
        updateLuaElementValue(newPoint, LuaElementType.Float3, "point", float3.New(0, 10 + i * 10, 0))
    end

    -- Open the Properties window 
    openInspector()
    showToast("You are very smart!")
end