~~NOTOC~~ ====== setTexture ====== [[developer_center:developer_editor:script:ui_event|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 ==== -- 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: * **playerid**: Target player * **uiid**: Parent UI container * **elementid**: Image element to modify * **url**: New texture ID === 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: * **Dynamic UI Modification**: Changing elements at runtime * **Player Interaction**: Responding to block clicks * **Texture Management**: Applying different images to UI components * **Component Targeting**: Using element IDs for precise control **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: * `uiid` (your custom UI's ID) * `elementid` (specific image element ID) * `url` (valid texture ID) 2. Ensure: * The UI is already created/visible * Texture IDs are preloaded 3. For multiple textures: * Store texture IDs in a table * Use logic to cycle through them === 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