Jump to content

just a question


Recommended Posts

hi, i need to know why is this doesn't work

function ylay() 
   wa = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
   
  
    showCursor(true) 
end 
 function wia() 
      destroyElement (wa) 
      showCursor(false) 
end 
addCommandHandler ( "y", ylay ) 
addEventHandler ( "onClientGUIClick",wa,wia) 
  
     

Link to comment

don't do destroyelement on GUIs. :? i don't understand what you're trying to do but here's an example

addEventHandler("onClientGUIClick",wa,function() 
    if ( source == wa) then 
           guiSetVisible(wa,false) 
           showCursor(false) 
       end 
   end ) 

Link to comment

you don't need destroyElement when you can hide it with guiSetVisible

local Button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
guiSetVisible(Button,false) 
  
function create() 
    guiSetVisible(Button,true) 
    showCursor(true) 
end 
addCommandHandler ( "y", create ) 
  
function delete() 
    showCursor(false) 
    guiSetVisible(Button,false) 
end 
addEventHandler("onClientGUIClick", Button, delete, false) 

Link to comment
you don't need destroyElement when you can hide it with guiSetVisible
local Button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
guiSetVisible(Button,false) 
  
function create() 
    guiSetVisible(Button,true) 
    showCursor(true) 
end 
addCommandHandler ( "y", create ) 
  
function delete() 
    showCursor(false) 
    guiSetVisible(Button,false) 
end 
addEventHandler("onClientGUIClick", Button, delete, false) 

thnx, but i need to know whats wrong with the one that i mad

Link to comment

Hey,

the problem with your script is that the wa variable doesn't exist when the addCommandHandler line gets executed, you can evade this like this:

function ylay() 
   wa = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
   showCursor(true) 
end 
 function wia() 
      if (source == wa) then --Checks if it is the button we are looking for or not 
      destroyElement (wa) 
      showCursor(false) 
      end 
end 
addCommandHandler ( "y", ylay ) 
addEventHandler ("onClientGUIClick",root,wia)  

see?, I used root as the second argument of the eventhandler so we don't get any error, and checked inside the function if the wa variable is the button we are looking for or not by using source.

Edited by Guest
Link to comment
Hey,

the problem with your script is that the marker variable doesn't exist when the addCommandHandler line gets executed, you can evade this like this:

function ylay() 
   wa = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
   showCursor(true) 
end 
 function wia() 
      if (source == wa) then --Checks if it is the marker we are looking for or not 
      destroyElement (wa) 
      showCursor(false) 
      end 
end 
addCommandHandler ( "y", ylay ) 
addEventHandler ("onClientGUIClick",root,wia)  

see?, I used root as the second argument of the eventhandler so we don't get any error, and checked inside the function if the marker is the marker we are looking for or not by using source.

but i wanted it to work when click the button ,and if i used root it will work wherever i press.

Link to comment
it's a button and not a marker, why do you need to do destroyelement on a button when you can use
  
guiSetVisible 
  

i don't want to use this script, i just want to know why it doesn't work

cuz i have many problems like this when i,m trying to make like those scripts

Link to comment
but i wanted it to work when click the button ,and if i used root it will work wherever i press

You have only one button without parents in your code and you will click only on this button

Edited by Guest
Link to comment

but i wanted it to work when click the button ,and if i used root it will work wherever i press.

yes, but I've added an extra if inside the function which checks if the clicked element is the button you created

if (source == wa) then 

and yea, I don't know why did I use the marker word instead of the button thx for saying(edited)

Link to comment

it's work as you wanted

i just want to know why my code isn't working, that's it

You have one button without any parents.Your button as guiRoot

function ylay() 
    wa = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
    showCursor(true) 
end 
addCommandHandler ( "y", ylay ) 
  
function wia() 
          destroyElement (wa) 
          showCursor(false) 
end 
addEventHandler ("onClientGUIClick",guiRoot,wia)  

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