Zcraks Posted August 26, 2019 Share Posted August 26, 2019 local button = {} function menu button[1] = ... button[2] = ... function click () if source == button ??????? and source ~= guiWind then if source == button[1] then ... How to check for all buttons? Link to comment
Addlibs Posted August 26, 2019 Share Posted August 26, 2019 (edited) local button = {} function createMenu() button[1] = ... button[2] = ... -- either add handlers yourself addEventHandler("onClientGUIClick", button[1], click, false) addEventHandler("onClientGUIClick", button[2], click, false) -- if you add a false after the function name (getPropagated parameter), the function won't trigger for the elements parents (e.g. the parent gui window) -- or use a loop here for i = 1, #button do -- start at i = 1 and perform the body of the block and increment i until i = #button (number of elements in button table) addEventHandler("onClientGUIClick", button[i], click, false) end end function click() -- beacuse getPropagated is set to false on all handlers, you don't need to test whether this is a valid source (that is, source will never be your guiwindow), all you need to do is branch depending on which button it is if source == button[1] then ... elseif source == button[2] then ... end end Would be a much better way of doing this, imo. I'm not sure but you may need to put the click function above the function with addEventHandlers. Edited August 26, 2019 by MrTasty Link to comment
Moderators IIYAMA Posted August 26, 2019 Moderators Share Posted August 26, 2019 1 hour ago, Zcraks said: How to check for all buttons? You can also attach the eventHandler to the parent GUI, if you have at least one GUI parent. local myWindow = guiCreateWindow ( 0, 0, 0.5, 0.4, "window", true ) local button = {} function click () if source ~= myWindow then if source == button[1] then elseif source == button[2] then end end end button[1] = guiCreateButton( 0.3, 0.1, 0.2, 0.1, "button 1!", true, myWindow ) -- 1 button[2] = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "button 2!", true, myWindow ) -- 2 addEventHandler("onClientGUIClick", myWindow, click, true) -- true = propagation enabled Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now