waleedrt Posted May 15, 2016 Share Posted May 15, 2016 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
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 i meat it creates the buttom i think thats the problem addEventHandler ( "onClientGUIClick",wa,wia) Link to comment
Bean666 Posted May 15, 2016 Share Posted May 15, 2016 what's that wa , wia? tell us what exactly u want to do. and wtf are you doing. Link to comment
Bean666 Posted May 15, 2016 Share Posted May 15, 2016 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
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 i want when i press the button it destroys its like an exit button, and wa wia should it mean something? Link to comment
BEN. Posted May 15, 2016 Share Posted May 15, 2016 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
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 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
BEN. Posted May 15, 2016 Share Posted May 15, 2016 also addEventHandler("onClientGUIClick", Button, delete, false) you kow why false? https://wiki.multitheftauto.com/wiki/In ... ng_the_GUI Link to comment
Feher Posted May 15, 2016 Share Posted May 15, 2016 (edited) 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 May 15, 2016 by Guest Link to comment
Bean666 Posted May 15, 2016 Share Posted May 15, 2016 it's a button and not a marker, why do you need to do destroyelement on a button when you can use guiSetVisible Link to comment
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 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
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 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
BEN. Posted May 15, 2016 Share Posted May 15, 2016 (edited) 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 May 15, 2016 by Guest Link to comment
Bean666 Posted May 15, 2016 Share Posted May 15, 2016 what is your main problem? i can barely understand your grammar. Link to comment
waleedrt Posted May 15, 2016 Author Share Posted May 15, 2016 what is your main problem? i can barely understand your grammar. i just want to know why my code isn't working, that's it Link to comment
Feher Posted May 15, 2016 Share Posted May 15, 2016 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
BEN. Posted May 15, 2016 Share Posted May 15, 2016 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
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