guiComboBoxGetItemText | Multi Theft Auto: Wiki Skip to content

guiComboBoxGetItemText

Client-side
Server-side
Shared

Pair: guiComboBoxSetItemText

This function retrieves the text from a specific combobox item.

OOP Syntax Help! I don't understand this!

Syntax

string|false guiComboBoxGetItemText ( ​gui-combobox comboBox, ​int itemId )
Required arguments
  • comboBox: The combobox containing the item you're interested in.
  • itemId: The index of the item. Indexing starts at 0.

Returns

Returns the text of the item if the arguments are right, false otherwise.

  • string|false: item-text

Code Examples

client

This outputs selected item's text to the chatbox.

local x,y = guiGetScreenSize()
local guiWindow = createWindow(x/2-500,y/2-500,500,500,"myWindow",false,nil)
local comboBox = guiCreateComboBox(0.1,0,1,0.8,0.8,"Select a value please",true,guiWindow)
guiComboBoxAddItem(comboBox,"value1")
addCommandHandler("getText",function()
local item = guiComboBoxGetSelected(comboBox)
if (item == -1) then
outputChatBox("No item selected!")
return
end
local text = guiComboBoxGetItemText(comboBox, item)
if text then
outputChatBox("You have selected: " .. text)
end
end)

See Also

GUI Functions