guiEditSetCaretIndex | Multi Theft Auto: Wiki Skip to content

guiEditSetCaretIndex

Client-side
Server-side
Shared

Pair: guiEditGetCaretIndex

This function sets the current position of the caret (the text cursor) within the edit box.

OOP Syntax Help! I don't understand this!

  • Method:gui-edit:setCaretIndex(...)
  • Variable: .caretIndex

Syntax

bool guiEditSetCaretIndex ( ​gui-edit guiEdit, ​int index )
Required arguments
  • guiEdit: The edit box to be changed.
  • index: An integer referring to the desired position within the box.

Returns

Returns true if the index was successfully set, false otherwise.

  • bool: result

Code Examples

client

This example makes the text cursor jump to the end of an edit box if the user is holding the Left Control button.

function moveToEndOnClick()
if (getKeyState("lctrl") and getElementType(source) == "gui-edit") then -- if the user is holding down left control
local text = guiGetText(source)
local textLength = string.len(text)
guiEditSetCaretIndex(source, textLength) -- set the caret index. No need to check if the clicked control is actually an edit box as this function won't work on other controls anyway
end
end
addEventHandler("onClientGUIClick", root, moveToEndOnClick) -- add an event handler for clicks

See Also

GUI Functions