Jump to content

[HELP] Bad Argument


Recommended Posts

I'm Tried to close window on Button Click but it Gives me bad Argument..see

Client:

        CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
        guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000")      

function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 

Error:

:84: Bad Argument @ 'addEventHandler' [Expected Element at argument 2, got nil] 

Link to comment

If your code looks like:

function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 
  
CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000") 

Then it will show the error bad argument.

So you have to correct it like this:

CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000") 
  
function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 

Link to comment
If your code looks like:
function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 
  
CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000") 

Then it will show the error bad argument.

So you have to correct it like this:

CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000") 
  
function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 

Actually not like how you said...It's:

        CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
        guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000")      
    end 
) 
function Marker() 
guiSetVisible (GUIEditor.window[1],true) 
showCursor ( true ) 
end 
addEvent ("Marker", true) 
addEventHandler ("Marker", getRootElement(), Marker) 
  
function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 
end 
addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 

Link to comment
oh i got it, you used event onClientResourceStart for create the gui window, button..

Move this line and put it inside event onClientResourceStart below the guiCreateButton.

addEventHandler ("onClientGUIClick", CloseButton, CloseShop) 

Alright i did it:

        CloseButton = guiCreateButton(432, 298, 108, 43, "Close", false, GUIEditor.staticimage[1]) 
        guiSetProperty(CloseButton, "NormalTextColour", "FFEF0000")  
        addEventHandler ("onClientGUIClick", CloseButton, CloseShop)         
    end 
) 
function Marker() 
guiSetVisible (GUIEditor.window[1],true) 
showCursor ( true ) 
end 
addEvent ("Marker", true) 
addEventHandler ("Marker", getRootElement(), Marker) 
  
function CloseShop() 
if guiGetVisible (GUIEditor.Window[1]) then 
   guiSetVisible (GuiEditor.Window[1], false) 
   showCursor (false) 
   end 

and Error now is:

:80: attempt to index field 'window' (a nil value) 

and :80: is

if guiGetVisible (GUIEditor.Window[1]) then 

Link to comment
Window ~> window

Thanks..work but i got another problem....It's with Trigger sides....i've triggerd client side and then in debugscript it says i triggerd client side but serverside not added...see

server side:

ShopMarker = createMarker(2285.8000488281,549.59997558594,6.8000001907349,"cylinder",1.5,0,125,250,153) 
  
function Marker(hitPlayer) 
    triggerClientEvent(hitPlayer,"Marker",getRootElement(),hitPlayer) 
end 
addEventHandler ("onMarkerHit",ShopMarker,Marker) 

client side:

function Marker() 
guiSetVisible (GUIEditor.window[1],true) 
showCursor ( true ) 
end 
addEvent ("Marker", true) 
addEventHandler ("Marker", getRootElement(), Marker) 

Error:

Server triggered clientside event Marker, but event is not added client side.  

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