pa3ck Posted October 2, 2013 Share Posted October 2, 2013 Hi MTA forumers, I'm trying to use the guiEditBox with a small button beside it and if you press the button it will output your message to the chat. I've done that without a problem BUT if I click on the gui itself ( not the button, anywhere else ) it does the same thing as the button, so outputs the text... I just don't know why and I can't figure it out. I include the short script too: function gui() gui = guiCreateWindow(739, 292, 244, 360, "GUI", false) guiWindowSetSizable(gui, false) guiSetVisible(gui, true) showCursor(true) guiEdit = guiCreateEdit(9, 41, 153, 30, "Enter your message", false, gui) Button = guiCreateButton(172, 41, 58, 31, "Send", false, gui) function writeToChat () local msg = guiGetText ( guiEdit ) outputChatBox (msg ) end addEventHandler ( "onClientGUIClick", Button, writeToChat ) end addCommandHandler('gtest', gui) Link to comment
Discord Moderators Zango Posted October 2, 2013 Discord Moderators Share Posted October 2, 2013 It's a good question and it's indeed quite strange. You could implement a check, in your function writeToChat, that ensures that the clicked GUI element is the button. Example: function gui() gui = guiCreateWindow(739, 292, 244, 360, "GUI", false) guiWindowSetSizable(gui, false) guiSetVisible(gui, true) showCursor(true) guiEdit = guiCreateEdit(9, 41, 153, 30, "Enter your message", false, gui) Button = guiCreateButton(172, 41, 58, 31, "Send", false, gui) function writeToChat () if (source ~= Button) then -- If the GUI element clicked differs from the "Button" element return false -- Exit end local msg = guiGetText ( guiEdit ) outputChatBox (msg ) end addEventHandler ( "onClientGUIClick", Button, writeToChat ) end addCommandHandler('gtest', gui) Link to comment
pa3ck Posted October 2, 2013 Author Share Posted October 2, 2013 I felt like I was so silly, but I'm happy it was not my mistake And thanks, it is working now, thanks for the quick support. 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