XetaQuake Posted February 2, 2008 Share Posted February 2, 2008 hi, i have starting with scripting and i have get it working to make a GUI window. I am realy happy but i have a problem with my "PLAY" button, when i click it, the window dont go away. Here is a snip from the button: exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) addEventHandler( "onClientClick", exitButton, exitTheInfoWindow ) function exitTheInfoWindow() guiSetVisible( joinInfos, false ) showCursor( false ) end can anybody help me? Link to comment
XetaQuake Posted February 2, 2008 Author Share Posted February 2, 2008 can nobody help me? i thing that some peaple here can help me in 1minute pleas. i currently learning lua, but i dont can it in one day Link to comment
Hedning Posted February 2, 2008 Share Posted February 2, 2008 http://development.mtasa.com/index.php? ... SetVisible its all there Link to comment
50p Posted February 2, 2008 Share Posted February 2, 2008 Don't use onClientClick, use onClientGUIClick instead. Link to comment
XetaQuake Posted February 2, 2008 Author Share Posted February 2, 2008 now i have exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) function exitTheInfoWindow() guiSetVisible( joinInfos, false ) showCursor( false ) end but the result is the same @Hedning: i already use guiSetVisible Link to comment
mabako Posted February 2, 2008 Share Posted February 2, 2008 you could try "debugscript 3" - I couldn't see an error from your code. Another idea might be a outputChatBox in function exitTheInfoWindow() - so you know whetever it's called AT ALL Link to comment
XetaQuake Posted February 3, 2008 Author Share Posted February 3, 2008 you could try "debugscript 3" - I couldn't see an error from your code. Another idea might be a outputChatBox in function exitTheInfoWindow() - so you know whetever it's called AT ALL good idea, i have tried it first with outputChatBox -> noting came than i have use debugscript 3, and he says bad argument @ addEventHandler, so the problem is the event. but i cant find any problems: addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) Link to comment
mabako Posted February 3, 2008 Share Posted February 3, 2008 you might need to add the function before assigning an event calling it. Link to comment
50p Posted February 3, 2008 Share Posted February 3, 2008 Try to use getRootElement() as the 2nd param. I used it and it worked for me. Link to comment
XetaQuake Posted February 3, 2008 Author Share Posted February 3, 2008 @mabako: i have tried exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) function exitTheInfoWindow() guiSetVisible( joinInfos, false ) showCursor( false ) end addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) noting change ;( @50p: can you explain me a little bit more? Where should I place exactly getRootElement? Link to comment
Hedning Posted February 3, 2008 Share Posted February 3, 2008 guiSetVisible( joinInfos, false ) to guiSetVisible( exitButton, false ) Link to comment
Mr.Hankey Posted February 3, 2008 Share Posted February 3, 2008 ah great to see this topic i got the same/a similar problem and was just about starting a new topic for it^^ First i started to look for something like this in the standart resource and found out that in the stealthmain_client.lua file the eventhandler for onClientGUIClick is placed in the same function where the button is created so i tried the same in my code... I used this: vehicles = { "rc_baron", "rc_tiger", "rc_goblin" } function spawn (button, state, absoluteX, absoluteY) outputChatBox ("Clicked") end function guiMenu () showCursor ( true ) Menu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your vehicle", true ) OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) guiWindowSetMovable ( Menu, false ) guiWindowSetSizable ( Menu, false ) GridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, Menu ) guiGridListSetSelectionMode ( GridList, 2 ) guiGridListAddColumn ( GridList, "Vehicles", 0.3 ) for key,vehicleName in pairs(vehicles) do local row = guiGridListAddRow ( GridList ) guiGridListSetItemText ( GridList, row, 1, vehicleName, false, false ) end addEventHandler ("onClientGUIClick", OKButton, spawn) end But what happened now was really strange. The Button went really dark as if it is placed behind the window and if i clicked on it nothing happened. But if i clicked on the border of the window somehow the function spawn was called... As if the declaration OKButton in the eventhandler also declares the parent elements of the button, the Window. I hope someone can help xeta and me with this problem =) Link to comment
Jumba' Posted February 3, 2008 Share Posted February 3, 2008 Try to use getRootElement() as the 2nd param. I used it and it worked for me. Yea, but wouldn't that cause the GUI window to close when whichever button is pressed? Link to comment
XetaQuake Posted February 3, 2008 Author Share Posted February 3, 2008 ah great to see this topic i got the same/a similar problem and was just about starting a new topic for it^^First i started to look for something like this in the standart resource and found out that in the stealthmain_client.lua file the eventhandler for onClientGUIClick is placed in the same function where the button is created so i tried the same in my code... I used this: vehicles = { "rc_baron", "rc_tiger", "rc_goblin" } function spawn (button, state, absoluteX, absoluteY) outputChatBox ("Clicked") end function guiMenu () showCursor ( true ) Menu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Select your vehicle", true ) OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) guiWindowSetMovable ( Menu, false ) guiWindowSetSizable ( Menu, false ) GridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, Menu ) guiGridListSetSelectionMode ( GridList, 2 ) guiGridListAddColumn ( GridList, "Vehicles", 0.3 ) for key,vehicleName in pairs(vehicles) do local row = guiGridListAddRow ( GridList ) guiGridListSetItemText ( GridList, row, 1, vehicleName, false, false ) end addEventHandler ("onClientGUIClick", OKButton, spawn) end But what happened now was really strange. The Button went really dark as if it is placed behind the window and if i clicked on it nothing happened. But if i clicked on the border of the window somehow the function spawn was called... As if the declaration OKButton in the eventhandler also declares the parent elements of the button, the Window. I hope someone can help xeta and me with this problem =) i thank you now the cursor go away when i clicked and i have make a outputChatBox ("Clicked") that shows to but, the window joinInfos dont go away, i think anything like this is not correct: guiSetVisible ( joinInfos, false ) can anybody help? I have a suspicion: my script need a guiSetVisible ( joinInfos, true ) befor i change it to false, is that possibly? ----- by the way, eXo|Mr.Hankey i will try to help you: change OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true, Menu ) to OKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "OK", true ) Link to comment
50p Posted February 3, 2008 Share Posted February 3, 2008 can anybody help?I have a suspicion: my script need a guiSetVisible ( joinInfos, true ) befor i change it to false, is that possibly? Is this what you want? You can set it to true whenever you want. When you change it to false it will simply disappear. I don't actually get your question. Link to comment
Mr.Hankey Posted February 3, 2008 Share Posted February 3, 2008 hm... well if i dont make the window the parent it works well but the thing is that if i assign the window as a parent and create the button AFTER all the other gui elements it works also until you click on the gridlist or the window... then the button switches to the background. So now i just made an event onClientGUIClick for the Window and everytime you click on something in the window it will bring the button back to the front using guiBringToFront (OKButton). Looks a bit buggy but it works and that's all i wanted =) Anyway thanks for the help xeta Link to comment
XetaQuake Posted February 3, 2008 Author Share Posted February 3, 2008 (edited) okok, i explain my problem better: i have getting it working to deactivate the cursor after klicking PLAY but the otherwise problem is: when i clicking on PLAY, the GUI window dont go away here is my complete code: edit: censored Edited February 3, 2008 by Guest Link to comment
Mr.Hankey Posted February 3, 2008 Share Posted February 3, 2008 hm.. maybe it's because you use local variables. In the scripting wiki examples it's always something like joinInfos = guiCreateWindow ( 0.30, 0.25, 0.4, 0.5, "Welcome", true ) --instead of local joinInfos = guiCreateWindow ( 0.30, 0.25, 0.4, 0.5, "Welcome", true ) Another thing is the end you're using at line 24 because. For what is it?! looks like a piece of code you forgot to erase^^ But because i create all those guiElement in a function that is called onPlayerJoin or onResourceStart i dont really know if it works then. Link to comment
XetaQuake Posted February 3, 2008 Author Share Posted February 3, 2008 eXo|Mr.Hankey, i thank you very very well! the LOCAL was the problem! now all working perfectly by the way: the "end" is from "function joinInfos()" at line 3 now i delete this thread from my favorites, thank @ all for help! Link to comment
Mr.Hankey Posted February 4, 2008 Share Posted February 4, 2008 np XetaQuake Now i went on with scripting and it lead me to new problems with triggerEvents but i think i can find solutions for that on my own =) Thx for everyone else who helped us with this problem! Link to comment
Frank-De-Ruiter Posted February 5, 2008 Share Posted February 5, 2008 exitButton = guiCreateButton( 0.30, 0.75, 0.4, 0.03, "Play", true ) addEventHandler( "onClientGUIClick", exitButton, exitTheInfoWindow ) function ( ) if (source == exitButton) then guiSetVisible( joinInfos, false ) showCursor( false ) end you forgot the: if (source == exitButton) then This tells activates the command when someone pushes the "Play" Button. Greatings Frank Link to comment
XetaQuake Posted February 5, 2008 Author Share Posted February 5, 2008 eXo|Mr.Hankey, i thank you very very well! the LOCAL was the problem! now all working perfectly it works already, but thanks for help Link to comment
Frank-De-Ruiter Posted February 6, 2008 Share Posted February 6, 2008 i know but mayby handy for some people ho don't know how to make buttons Link to comment
Mr.Hankey Posted February 6, 2008 Share Posted February 6, 2008 frank you dont have to check if the source is the button because if you set the root element of the eventhandler to the button element the function wont be called if you click for example on another button so it can only be true and the source element will never be another then the button you defined as the root element Link to comment
Frank-De-Ruiter Posted February 6, 2008 Share Posted February 6, 2008 okay your right about that:P but i find this much more handy 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