OnClientGUIClick: Difference between revisions
Jump to navigation
Jump to search
(→Example: added false to addEventHandler, I had people asking me why the example doesn't work) |
(→Example: the example didn't work at all) |
||
Line 19: | Line 19: | ||
This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the Chat Box. | This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the Chat Box. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
--create our button | -- when client's resource start, create the gui | ||
btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) | function initGUI( ) | ||
--create our button | |||
btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) | |||
--Create an edit box and define it as "editBox". | --Create an edit box and define it as "editBox". | ||
editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true ) | editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true ) | ||
guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this | guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this | ||
end | |||
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) | |||
--setup our function to output the message to the chatbox | --setup our function to output the message to the chatbox |
Revision as of 18:13, 15 August 2008
This article needs checking. | |
Reason(s): middle button does not trigger this event.--50pence 12:19, 19 May 2008 (CDT) |
This event is fired when the user clicks a GUI element.
Parameters
string button, string state, int absoluteX, int absoluteY
- button: the name of the mouse button that the GUI element was clicked with, can be left, right, or middle.
- state: the state of the mouse button, will be down if the mouse button was pushed, or up if it was released.
- absoluteX: the X position of the mouse cursor, in pixels, measured from the left side of the screen.
- absoluteY: the Y position of the mouse cursor, in pixels, measured from the top of the screen.
Source
The source of this event is the GUI element that was clicked.
Example
This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the Chat Box.
-- when client's resource start, create the gui function initGUI( ) --create our button btnOutput = 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 ) guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) --setup our function to output the message to the chatbox function outputEditBox (button) if button == "left" then local text = guiGetText ( editBox )--get the text from the edit box outputChatBox ( text ) --output that text end end --and attach our button to the outputEditBox function addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false )
See Also
GUI events
Input
GUI
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled