GuiEditSetMaxLength: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (t)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Client function}}
This function sets the maximum text length that can be typed into an edit box.
This function sets the maximum text length that can be typed into an edit box.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool guiEditSetMaxLength ( element theElement, int length )
bool guiEditSetMaxLength ( element guiEdit, int length )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[Element/GUI/Edit_field|GuiEdit]]:setMaxLength|maxLength|guiEditGetMaxLength}}


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
 
*'''theElement:''' The edit box to be changed.
*'''theElement:''' The edit box to be changed.
*'''lenth:''' An integer indicating the maximum number of characters that can be typed into the box.
*'''length:''' An integer indicating the maximum number of characters that can be typed into the box.


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if the max length was set successfully, ''false'' otherwise.
Returns ''true'' if the function is successful, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example creates an edit box with a limit on text length, alongside an "Output!" button. When the button is clicked, it will output the message in the edit box into the chatbox.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
-- create our button
blabhalbalhb --abababa
button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
--This line does this...
-- create an edit box and define it as "editBox".
mooo
editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
-- set a maximum text length of 128 characters
guiEditSetMaxLength ( editBox, 128 )
 
-- setup our function to output the message to the chatbox
function outputEditBox ()
        local text = guiGetText ( editBox )  -- get the text from the edit box
        outputChatBox ( text )                -- output that text
end
addEventHandler ( "onClientGUIClick", button, outputEditBox )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{GUI_functions}}
{{GUI_functions}}
[[Category:Incomplete]]
{{GUI_events}}
[[RU:guiEditSetMaxLength]]

Latest revision as of 21:53, 12 December 2020

This function sets the maximum text length that can be typed into an edit box.

Syntax

bool guiEditSetMaxLength ( element guiEdit, int length )

OOP Syntax Help! I don't understand this!

Method: GuiEdit:setMaxLength(...)
Variable: .maxLength
Counterpart: guiEditGetMaxLength


Required Arguments

  • theElement: The edit box to be changed.
  • length: An integer indicating the maximum number of characters that can be typed into the box.

Returns

Returns true if the max length was set successfully, false otherwise.

Example

This example creates an edit box with a limit on text length, alongside an "Output!" button. When the button is clicked, it will output the message in the edit box into the chatbox.

-- create our button
button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
-- create an edit box and define it as "editBox".
editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
-- set a maximum text length of 128 characters
guiEditSetMaxLength ( editBox, 128 )

-- setup our function to output the message to the chatbox
function outputEditBox ()
        local text = guiGetText ( editBox )   -- get the text from the edit box
        outputChatBox ( text )                -- output that text
end
addEventHandler ( "onClientGUIClick", button, outputEditBox )

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows

Input

GUI