Jump to content

GUI buttons


KaMeR

Recommended Posts

why the two buttons have same effect when clicking whats wrong?

    closeButton = guiCreateButton( 0.1, 0.9, 0.8, 0.1, "click here to close", true, windowForm) 
    button = guiCreateButton( 0.7, 0.4, 0.2, 0.1, "test", true, windowForm  ) 
function bClose ( closeButton ) 
                guiSetVisible ( windowForm, false ) 
                showCursor ( false ) 
end 
  
function test( button ) 
        outputChatBox ( "test" ) 
end 
  
addEventHandler ( "onClientGUIClick", getRootElement(), bClose ) 
addEventHandler ( "onClientGUIClick", getRootElement(), test ) 

Link to comment

Because you're assigning your onClientGUIClick event handlers to the root element, not the button you want them to react to. That means the handler will be executed whenever any GUI element has been clicked, so the GUI will first be hidden and then you get the "test" output for both buttons.

To fix this, use the button you want the handler to react to in addEventHandler:

addEventHandler ( "onClientGUIClick", closeButton, bClose ) 
addEventHandler ( "onClientGUIClick", button, test ) 

BTW, you should not name function arguments like global variables or the globals will be inaccessible in the function.

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