Jump to content

Problem with GUI button not working


megaman54

Recommended Posts

Hello! I'm making a login GUI for my server but i have faced this problem: when i press the gui button, nothing happens. I have scripted event for that button but for some reason it wont work. Here is my code:

addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), 
function ( ) 
    if(source == loginButton)then 
        local username = guiGetText(usernameBoxLogin) 
        local password = guiGetText(passwordBoxLogin) 
        if(username)then 
            if(password)then 
                triggerServerEvent("server_DoLogin", getRootElement(), username, password) 
            end 
        end 
    elseif(source == loginClearButton)then 
        guiSetText(usernameBoxLogin, "") 
        guiSetText(passwordBoxLogin, "") 
    elseif(source == registerButton)then 
        local regUsername = guiGetText(usernameBoxRegister) 
        local regPassword = guiGetText(passwordBoxRegister) 
        local regEmail = guiGetText(emailBoxRegister) 
        if(regUsername)then 
            if(regPassword)then 
                if(regEmail)then 
                    triggerServerEvent("server_doRegister", getLocalPlayer()) 
                end 
            end 
        end 
    elseif(source == registerClearButton)then 
        guiSetText(usernameBoxRegister, "") 
        guiSetText(passwordBoxRegister, "") 
        guiSetText(emailBoxRegister, "") 
    end 
end 
) 

It might be because of those "elseif" and "if" things or some misplaced "end" 's but i'm not so good with those "if" 's yet... :?

Link to comment

where is the button itself? and what is supposed to happen? where's the server part?

ps:

-- instead of 
if a then 
  if b then 
    if c then 
     
    end 
  end 
end 
-- you can do: 
if a and b and c then 
  
end   
  
--also you can use variables instead of redundant function calls: 
  
getResourceRootElement(getThisResource()) == resourceRoot 
-- can be replaced by resourceRoot predefined variable. 
  
getLocalPlayer() == localPlayer  
-- can be replaced by localPlayer predefined variable. 
  
getRootElement() == root 
-- can be replaced by root predefined variable. 
  

Link to comment

Well here is the server part, its only in debug stage so it doesnt have any actual stuff yet:

function debug() 
    outputChatBox("triggered: server_DoLogin") 
end 
addEvent("server_DoLogin", true) 
addEventHandler("serer_DoLogin", getRootElement(), debug) 
  
function debug2() 
    outputChatBox("triggered: server_DoRegister") 
end 
addEvent("server_DoRegister", true) 
addEventHandler("server_DoRegister", getRootElement(), debug2) 
  
function openLoginScreenOnRequest(thePlayer) 
    triggerClientEvent(thePlayer, "client_openLoginScreen", getRootElement()) 
    outputChatBox("loginScreen tirggered!") 
end 
addEvent("server_requestOpenLoginScreen", true) 
addEventHandler("server_requestOpenLoginScreen", getRootElement(), openLoginScreenOnRequest) 

and here is for buttons:

loginButton = guiCreateButton(10,108,84,27,"Login",false,GUIEditor_Tab[1]) clearButtonLogin = guiCreateButton(220,108,84,27,"Clear",false,GUIEditor_Tab[1]) registerButton = guiCreateButton(13,117,102,30,"Register",false,GUIEditor_Tab[2]) clearButtonRegister = guiCreateButton(199,117,102,30,"Clear",false,GUIEditor_Tab[2]) 

Link to comment
Ahh thanks :D dint see that :oops:. But when testing the clear buttons, they do nothing. I did script functions to them but they seem not to work or i did something wrong. Also the clientside script doesnt check that the login and register text fields actually have text in them.

1. you create buttons in clearButtonLogin/clearButtonRegister but check for source in loginClearButton/registerClearButton, which are totally different names.

2. guiGetText() probably returns an empty string (not nil/false) in case of empty edit field. try "if #guiGetText(yourEditboxName) > 0 then"

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