guiComboBoxGetSelected | Multi Theft Auto: Wiki Skip to content

guiComboBoxGetSelected

Client-side
Server-side
Shared

Pair: guiComboBoxSetSelected

This function returns the index of the selected combobox item.

OOP Syntax Help! I don't understand this!

Syntax

int|nil guiComboBoxGetSelected ( ​gui-combobox comboBox )
Required arguments
  • comboBox: The combobox you want to know the selected item index of.

Returns

Returns the index of the selected item if the specified combobox is valid and has a selected item, -1 if no item is selected, nil otherwise.

  • int|nil: index

Code Examples

client

This example outputs selected item's text and ID to the chat.

local comboBox = guiCreateComboBox(300, 300, 200, 100, "Select an item", false)
guiComboBoxAddItem(comboBox, "Item 1")
guiComboBoxAddItem(comboBox, "Item 2")
addCommandHandler("getSelected", function(command)
local item = guiComboBoxGetSelected(comboBox)
if (item == -1) then
outputChatBox("No item selected!")
return
end
local text = guiComboBoxGetItemText(comboBox, item)
outputChatBox("Currently selected item with ID: " .. tostring(item) .. " and with text: " .. text)
end)

See Also

GUI Functions