Jump to content

GUI problem [button]


brocky

Recommended Posts

Hey, I don't know whats wrong in this guy. any ideas?

GUIEditor = {
    button = {},
    window = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1])
        button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1])    
    end
)

        
         function closeButton()
if button1 == source then
  outputChatBox("Hey")
end
end
    addEventHandler("onClientGUIClick",button1,closeButton,false)

 

Link to comment

;)  ;)  ;)  ;)  ;)  ;)

Client Side :-

GUIEditor = {
    button = {},
    window = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1])
        button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1])  
    end
)

function closeButton()
    if source == button1 then
        outputChatBox("Hey")
    end
end
addEventHandler("onClientGUIClick", resourceRoot, closeButton)

Or ,

Client Side :-

GUIEditor = {
    button = {},
    window = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1])
        button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1])  
		addEventHandler("onClientGUIClick", button1, closeButton)
    end
)

function closeButton()
    outputChatBox("Hey")
end

 

Edited by DeadthStrock
Link to comment
1 hour ago, DeadthStrock said:

;)  ;)  ;)  ;)  ;)  ;)

Client Side :-


GUIEditor = {
    button = {},
    window = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1])
        button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1])  
    end
)

function closeButton()
    if source == button1 then
        outputChatBox("Hey")
    end
end
addEventHandler("onClientGUIClick", resourceRoot, closeButton)

Or ,

Client Side :-


GUIEditor = {
    button = {},
    window = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        GUIEditor.window[1] = guiCreateWindow(563, 204, 519, 491, "Rules and Regulation", false)
        guiWindowSetSizable(GUIEditor.window[1], false)

        GUIEditor.memo[1] = guiCreateMemo(9, 29, 500, 418, "", false, GUIEditor.window[1])
        button1 = guiCreateButton(18, 449, 491, 32, "I agree", false, GUIEditor.window[1])  
		addEventHandler("onClientGUIClick", button1, closeButton)
    end
)

function closeButton()
    outputChatBox("Hey")
end

 

No, your first option is correct, not the second.

Link to comment
9 minutes ago, gSub said:

Compatibility issues if you put the GUI element in the event handler

Quoted :- https://wiki.multitheftauto.com/wiki/GuiCreateButton

--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 )
-- and attach our button to the outputEditBox function
addEventHandler ( "onClientGUIClick", editBox, outputEditBox )
guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this

--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 )

          MTA:Wiki also guide that...!! Well Well as you said Compatibility may issues if we put the GUI element in the event handler.

 

Edited by DeadthStrock
Link to comment
4 minutes ago, DeadthStrock said:

Quoted :- https://wiki.multitheftauto.com/wiki/GuiCreateButton


--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 )
-- and attach our button to the outputEditBox function
addEventHandler ( "onClientGUIClick", editBox, outputEditBox )
guiEditSetMaxLength ( editBox, 128 ) --the max chatbox length is 128, so force this

--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 )

          MTA:Wiki also guide that...!! Well Well as you said Compatibility may issues if we put the GUI element in the event handler.

 

Yep, and I still stand by word. 

the GUI sometimes calculates the actual button element a bit larger than the actual displayed unit, or since it's attached to the GUI window, it sometimes confuses that as well. So that means when you click outside of a button, it triggers the button.

Feel free to use any method you like, but what I use to avoid any type of issue is the first solution.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...