Jump to content

GUI problem


pa3ck

Recommended Posts

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

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

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