Jump to content

Bad argument @ Event handler


Donny7878

Recommended Posts

I seem to have an issue here but I can't work out what is "bad" about it.

-- top of script
local JoinBtn = nil
-- called when the resource starts, it creates the GUI element (button)
JoinBtn = guiCreateButton( 0.800, 0.950, 0.100, 0.050, "Join", 	 true, MainBgdImg )				
-- above the event handler
function PlayerRequestJoin( button )
--some code, if ( button == "left" etc, this is the mouse button not the element (source)
end
--bottom of script
addEventHandler( "onClientGUIClick", JoinBtn, PlayerRequestJoin, false )

The bad argument is on the last line there, the event handler. I've been working off these pages -> OnClientGUIClick & AddEventHandler.

From what I understand I have to create the variable for the button, create the button and assign it's element id or whatever you would say to the variable I created and now I add an event for the gui element (button I created) being clicked in which case the handler function I linked in the event handler should fire with the button element (the one clicked) being it's source (JoinBtn). If this is correct then I thought I had done that and maybe I have overlooked something or I'm not understanding it correctly.

Sorry to keep asking these question, just having trouble adjusting to the way it works.

Link to comment

creating gui outside a function is very temperamental and generally not a good idea, moving your gui and your onClientGUIClick event handler into an onClientResourceStart handle should sort this out (assuming there are no errors with your button code, eg: MainBgdImg exists)

Link to comment

moving your gui and your onClientGUIClick event handler into an onClientResourceStart handle should sort this out

Indeed this was the case, I should of picked up on that sooner.

The code was like this when it wasn't working:

-- gui function
   JoinBtn = guiCreateButton( 0.800, 0.950, 0.100, 0.050, "Join",     true, MainBgdImg )            
end
 
addEventHandler( "onClientGUIClick", JoinBtn, PlayerRequestJoin, false )

But when I changed it to this it works:

-- gui function
   JoinBtn = guiCreateButton( 0.800, 0.950, 0.100, 0.050, "Join",     true, MainBgdImg )            
   addEventHandler( "onClientGUIClick", JoinBtn, PlayerRequestJoin, false )
end

Thanks for the help again dude, it's apreciated !

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