DgsMenuSetItemText
Jump to navigation
Jump to search
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)
See Also
Author
This documentation was created by Mohab.