DgsMenuSetItemText: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Client function}} __NOTOC__ This function changes the displayed text of an existing menu item. ==Syntax== <syntaxhighlight lang="lua"> bool dgsMenuSetItemText ( element menu, int uniqueID, string text ) </syntaxhighlight> ===Required Arguments=== *'''menu:''' The DGS menu element containing the item *'''uniqueID:''' The unique ID of the menu item (returned by dgsMenuAddItem) *'''text:''' The new text to display for this menu item ===Returns=== Returns ''true'' i...") |
No edit summary |
||
Line 35: | Line 35: | ||
addEventHandler("onDgsMenuSelect", menu, function(subMenu, uniqueID) | addEventHandler("onDgsMenuSelect", menu, function(subMenu, uniqueID) | ||
if uniqueID == -1 then return end | if uniqueID == -1 then return end | ||
local command = dgsMenuGetItemCommand(source, uniqueID) | local command = dgsMenuGetItemCommand(source, uniqueID) | ||
if command == "start" then | if command == "start" then | ||
Line 54: | Line 54: | ||
return | return | ||
end | end | ||
dgsMenuHide(source) | dgsMenuHide(source) | ||
end, false) | end, false) | ||
Line 66: | Line 66: | ||
==Author== | ==Author== | ||
[[User:Mohab|Mohab]]. | |||
[[Category:DGS_functions]] | [[Category:DGS_functions]] |
Revision as of 04:47, 10 July 2025
This function changes the displayed text of an existing menu item.
Syntax
bool dgsMenuSetItemText ( element menu, int uniqueID, string text )
Required Arguments
- menu: The DGS menu element containing the item
- uniqueID: The unique ID of the menu item (returned by dgsMenuAddItem)
- text: The new text to display for this menu item
Returns
Returns true if the text was set successfully, false otherwise.
Examples
loadstring(exports.dgs:dgsImportFunction())()-- load functions -- Create a menu with a toggle option local menu = dgsCreateMenu(200, 200, 160, 120, false) dgsMenuAddItem(menu, "Start Game", "start") local soundItem = dgsMenuAddItem(menu, "Sound: ON", "toggle_sound") dgsMenuAddItem(menu, "Exit", "exit") -- Show the menu dgsMenuShow(menu) -- Track sound state local soundEnabled = true -- Handle menu selections addEventHandler("onDgsMenuSelect", menu, function(subMenu, uniqueID) if uniqueID == -1 then return end local command = dgsMenuGetItemCommand(source, uniqueID) if command == "start" then outputChatBox("Starting game...") elseif command == "toggle_sound" then -- Toggle sound state and update menu text soundEnabled = not soundEnabled if soundEnabled then dgsMenuSetItemText(source, soundItem, "Sound: ON") outputChatBox("Sound enabled") else dgsMenuSetItemText(source, soundItem, "Sound: OFF") outputChatBox("Sound disabled") end return -- Don't hide menu for toggle elseif command == "exit" then dgsMenuHide(source) return end dgsMenuHide(source) end, false)