===== setText API for Customui =====
[[developer_center:developer_editor:script:ui_event|From Customui Class]]
Customui:setText(playerid, uiid, elementid, text)
**API description**
The main purpose of this method is to set the content of the text symbol
^ Parameters ^ Types ^ Info ^
| playerid | number | player ID |
| uiid | string | the ID of interface |
| elementid | string | the ID of component |
| text | string | value of text to be parsed |
| animid | number | animation ID (optinal) |
| time | number | animation duration (optional & minimum is 0.1) |
| mode | number | playback mode (default) |
^ Return ^ value ^ type ^
| Error Code 0 is Success | 0 or 1001 | number |
==== Examples ====
--This function is executed when the player clicks on the block
local function clickblock(event)
local playerid = event.eventobjid --Click on the player's mini number of the block
local uiid = "6986982063319417057"--Interface ID
local elementid ="6986982063319417057_1"--Text element id
local text="Hello"-- The text content to be set
--Set the display of the player's text ui element
Customui:setText(playerid, uiid, elementid, text)
end
-- Register Event for Player.ClickBlock
ScriptSupportEvent:registerEvent([=[Player.ClickBlock]=], clickblock)
==== Lua Code Explanation: Click Block Event Handler ====
This Lua code creates an event handler that responds when a player clicks on a block in the game.
=== Function Definition ===
local function clickblock(event)
* Declares a function named **clickblock** that triggers on the event
* The **event** parameter contains information about the interaction
=== Getting Player ID ===
local playerid=event.eventobjid
* Extracts the **player's unique identifier** from the event object
* Identifies which player clicked the block
=== UI Configuration ===
local uiid="6986982063319417057" // Interface ID
local elementid="6986982063319417057_1" // Text element ID
local text="Hello" // Text content to display
* **uiid**: Unique identifier for the UI component
* **elementid**: Specific text element within the UI
* **text**: The message that will appear ("Hello")
=== Displaying the Text ===
Customui:setText(playerid, uiid, elementid, text)
* Calls the game's **CustomUI system** to show text to the player
* Parameters:
* **playerid** → Which player sees it
* **uiid** → Target UI component
* **elementid** → Specific element to modify
* **text** → Message content
=== Event Registration ===
ScriptSupportEvent:registerEvent([=[Player.ClickBlock]=], clickblock)
* Registers the **clickblock** function as a handler for **Player.ClickBlock** events
* Syntax breakdown:
* **[=[Player.ClickBlock]=]** → The event type (block clicks)
* **clickblock** → Handler function name
=== Notes ===
This demonstrates:
* **Event-driven programming** (responding to player actions)
* **Game engine API usage** (CustomUI system)
* **Basic Lua syntax** (functions, variables)
* **Game development concepts** (player interaction, UI updates)
**Result**: When any player clicks a block, they see "Hello" in a UI element.
==== Animation for Set a Text ====
^ ID ^ Name ^
| 40001 | Typewriter |
| 0 | Default |
Example :
-- Let's assume UIID and Element id is already defined
-- This Will set text with _Typewriter_ animation in 1 seconds (default playback once)
Customui:setText(1029380338, uiid , elementid, text , 40001 , 1)