GuiCheckBoxGetSelected: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(OOP syntax)
 
(5 intermediate revisions by 3 users not shown)
Line 6: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool guiCheckBoxGetSelected ( element theCheckbox )
bool guiCheckBoxGetSelected ( element theCheckbox )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[Element/GUI/Checkbox|GuiCheckBox]]:getSelected|selected|guiCheckBoxSetSelected}}


===Required Arguments===  
===Required Arguments===  
Line 15: Line 16:


==Example==
==Example==
This example makes a different beep based on the state when any checkbox has been clicked.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onClick (button, state, absoluteX, absoluteY) -- on Gui Click Func.
function checkboxBleepWhenClicked()
if ( source == myButton) then
    if ( getElementType(source) == "gui-checkbox" ) then -- Is the element clicked a checkbox?
 
        if ( guiCheckBoxGetSelected(source) ) then
isSelected = guiCheckBoxGetSelected(CheckBox) -- check if the check box is selected
            playSoundFrontEnd(1) -- If the checkbox is selected play sound 1.
        else
if isSelected == true then -- if selected then
            playSoundFrontEnd(2) -- If the checkbox isn't selected play sound 2.
outputChatBox("The CheckBox  is Selected")
        end
else -- else if its not selected
    end
outputChatBox("The CheckBox  is not Selected")
end
 
end
end
end
addEventHandler ("onClientGUIClick", getRootElement(), onClick) -- adding event handler for on click
addEventHandler("onClientGUIClick", root, checkboxBleepWhenClicked, false)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{GUI_functions}}
{{GUI_functions}}
[[Category:Needs_Example]]
{{GUI_events}}

Latest revision as of 20:34, 7 November 2018

This function gets a checkbox's selection state.

Syntax

bool guiCheckBoxGetSelected ( element theCheckbox )

OOP Syntax Help! I don't understand this!

Method: GuiCheckBox:getSelected(...)
Variable: .selected
Counterpart: guiCheckBoxSetSelected


Required Arguments

  • theCheckbox : The checkbox you wish to retrieve the selection state of.

Returns

Returns true if the checkbox is selected, false if it is not.

Example

This example makes a different beep based on the state when any checkbox has been clicked.

function checkboxBleepWhenClicked()
    if ( getElementType(source) == "gui-checkbox" ) then -- Is the element clicked a checkbox?
        if ( guiCheckBoxGetSelected(source) ) then
            playSoundFrontEnd(1) -- If the checkbox is selected play sound 1.
        else
            playSoundFrontEnd(2) -- If the checkbox isn't selected play sound 2.
        end
    end
end
addEventHandler("onClientGUIClick", root, checkboxBleepWhenClicked, false)

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