setTexture

From Customui Class

  Customui:setTexture(playerid, uiid, elementid, url)

API Description The main function of this method: Set the texture of an image element in a custom UI.

Parameters Types Info
playerid number Player ID
uiid string The ID of the custom UI
elementid string The ID of the image element
url string The texture ID to apply
Return Value Type
ErrorCode.OK (0) number

Examples

setTexture_Example.lua
-- This function executes when a player clicks a block
local function clickblock(event)
    local playerid = event.eventobjid  -- Player ID who clicked the block
    local uiid = "6986982063319417057"  -- Replace with your UI ID
    local elementid = "6986982063319417057_3"  -- Replace with your image element ID
    local url = "block_100"  -- Replace with your texture ID
 
    -- Set the texture for the player's UI image element
    Customui:setTexture(playerid, uiid, elementid, url)
end
-- Register event for Player.ClickBlock
ScriptSupportEvent:registerEvent([=[Player.ClickBlock]=], clickblock)

Lua Code Explanation: Texture Setting

This Lua code demonstrates how to change an image element's texture when a player clicks a block.

Function Definition

local function clickblock(event)

* Declares the clickblock function for `Player.ClickBlock` events * event parameter contains the interaction data

Parameter Extraction

local playerid = event.eventobjid

* Gets the player ID from the event object * Identifies which player triggered the action

UI Configuration

local uiid = "6986982063319417057"
local elementid = "6986982063319417057_3"
local url = "10010"

* uiid: The custom UI's identifier * elementid: Specific image component to modify * url: Texture ID to apply * Note: All are placeholders - replace with your actual IDs

Texture Setting

Customui:setTexture(playerid, uiid, elementid, url)

* Calls the Customui API to change the texture * Parameters:

Event Registration

ScriptSupportEvent:registerEvent([=[Player.ClickBlock]=], clickblock)

* Links the function to block-click events * Event type: `Player.ClickBlock` (triggered by any block interaction)

Educational Notes

Key concepts demonstrated:

Result: Clicking any block changes the specified image's texture for the interacting player.

Important Notes

1. Replace all placeholder IDs with your actual values:

2. Ensure:

3. For multiple textures:

Troubleshooting

If the texture doesn't change: 1. Verify all IDs are correct 2. Check if the UI is visible 3. Confirm the texture ID exists 4. Ensure the event is properly registered