Jump to content

guiGetText() error


Tomc0

Recommended Posts

Posted

Hello.

I have a little problem with the guiGetText() function.

So, I'm doing a register/login GUI form, and I want to get the edit box's text.

I made the GUI design with the QT to Lua program.

In the code, there are so many GUI button, label, edit creation functions, so I'm not going to post the whole code.

function drawWindow() 
   gui = {} 
   gui._placeHolders = {} 
   gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "Login/Register", false) 
   gui["tabWidget"] = guiCreateTabPanel(0, 20, 251, 181, false, gui["_root"]) 
   gui["tab_2"] = guiCreateTab("Register", gui["tabWidget"]) 
  
   gui["registerUsernameEdit"] = guiCreateEdit(110, 10, 113, 20, "", false, gui["tab_2"]) 
   guiEditSetMaxLength(gui["registerUsernameEdit"], 32767) 
     
   gui["registerPasswordEdit"] = guiCreateEdit(110, 40, 113, 20, "", false, gui["tab_2"]) 
   guiEditSetMaxLength(gui["registerPasswordEdit"], 32767) 
     
   gui["registerPasswordEditRepeat"] = guiCreateEdit(110, 70, 113, 20, "", false, gui["tab_2"]) 
   guiEditSetMaxLength(gui["lineEdit"], 32767) 
     
   gui["registerButton"] = guiCreateButton(52,105, 131, 23, "Register", false, gui["tab_2"]) 
   if on_registerButton_clicked then 
       addEventHandler("onClientGUIClick", gui["registerButton"], on_registerButton_clicked,false) 
   end 
     
   username = guiGetText(gui["registerUsernameEdit"]) 
   pw = guiGetText(gui["registerPasswordEdit"]) 
   pw2 = guiGetText(gui["registerPasswordEditRepeat"]) 
     
   return gui, windowWidth, windowHeight  
end 
addEventHandler("onClientResourceStart",getRootElement(),drawWindow) 
  
function on_registerButton_clicked()          
    outputChatBox(username) 
    outputChatBox(pw) 
    outputChatBox(pw2) 
end 

So, the problem:

If I click the Register button, the chatbox just outputs nothing, so I think the program can't get the values of the edit boxes.

If someone wants to see that, here's the whole code:

function drawWindow() 
    showCursor(true) 
  
    gui = {} 
    gui._placeHolders = {} 
     
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 250, 195 
    local left = screenWidth/2 - windowWidth/2 
    local top = screenHeight/2 - windowHeight/2 
    gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "Login/Register", false) 
    guiWindowSetSizable(gui["_root"], false) 
     
    gui["tabWidget"] = guiCreateTabPanel(0, 20, 251, 181, false, gui["_root"]) 
     
    gui["tab"] = guiCreateTab("Login", gui["tabWidget"]) 
     
    gui["loginButton"] = guiCreateButton(40, 100, 141, 21, "Login", false, gui["tab"]) 
    if on_loginButton_clicked then 
        addEventHandler("onClientGUIClick", gui["loginButton"], on_loginButton_clicked, false) 
    end 
     
    gui["label"] = guiCreateLabel(20, 30, 61, 16, "Username:", false, gui["tab"]) 
    guiLabelSetHorizontalAlign(gui["label"], "left", false) 
    guiLabelSetVerticalAlign(gui["label"], "center") 
     
    gui["label_2"] = guiCreateLabel(20, 60, 51, 16, "Password:", false, gui["tab"]) 
    guiLabelSetHorizontalAlign(gui["label_2"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_2"], "center") 
     
    gui["loginUserNameEdit"] = guiCreateEdit(90, 30, 113, 20, "", false, gui["tab"]) 
    guiEditSetMaxLength(gui["loginUserNameEdit"], 32767) 
     
    gui["loginPasswordEdit"] = guiCreateEdit(90, 60, 113, 20, "", false, gui["tab"]) 
    guiEditSetMaxLength(gui["loginPasswordEdit"], 32767) 
     
    gui["tab_2"] = guiCreateTab("Register", gui["tabWidget"]) 
     
    gui["label_3"] = guiCreateLabel(10, 10, 61, 16, "Username:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_3"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_3"], "center") 
     
    gui["label_4"] = guiCreateLabel(10, 40, 61, 16, "Password:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_4"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_4"], "center") 
     
    gui["label_5"] = guiCreateLabel(10, 70, 91, 16, "Password again:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_5"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_5"], "center") 
     
    gui["registerUsernameEdit"] = guiCreateEdit(110, 10, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["registerUsernameEdit"], 32767) 
     
    gui["registerPasswordEdit"] = guiCreateEdit(110, 40, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["registerPasswordEdit"], 32767) 
     
    gui["registerPasswordEditRepeat"] = guiCreateEdit(110, 70, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["lineEdit"], 32767) 
     
    gui["registerButton"] = guiCreateButton(52,105, 131, 23, "Register", false, gui["tab_2"]) 
    if on_registerButton_clicked then 
        addEventHandler("onClientGUIClick", gui["registerButton"], on_registerButton_clicked,false) 
    end 
     
    username = guiGetText(gui["registerUsernameEdit"]) 
    pw = guiGetText(gui["registerPasswordEdit"]) 
    pw2 = guiGetText(gui["registerPasswordEditRepeat"]) 
     
    return gui, windowWidth, windowHeight     
end 
addEventHandler("onClientResourceStart",getRootElement(),drawWindow) 
  
function on_registerButton_clicked()          
    outputChatBox(username) 
    outputChatBox(pw) 
    outputChatBox(pw2) 
end 

Thanks for the help.

Posted

WARNING: tg\RegisterLogin.lua58: Bad argument @ 'guiEditSetMaxLength' [Expected gui-element at argument 1, got nil]

But that's not my problem, that was just a simple bug, I fixed it. :S

Posted

I'm not sure this will works, try it.

function drawWindow() 
gui = {} 
gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "Login/Register", false) 
gui["tabWidget"] = guiCreateTabPanel(0, 20, 251, 181, false, gui["_root"]) 
gui["tab_2"] = guiCreateTab("Register", gui["tabWidget"]) 
  
gui["registerUsernameEdit"] = guiCreateEdit(110, 10, 113, 20, "", false, gui["tab_2"]) 
guiEditSetMaxLength(gui["registerUsernameEdit"], 32767) 
    
gui["registerPasswordEdit"] = guiCreateEdit(110, 40, 113, 20, "", false, gui["tab_2"]) 
guiEditSetMaxLength(gui["registerPasswordEdit"], 32767) 
    
gui["registerPasswordEditRepeat"] = guiCreateEdit(110, 70, 113, 20, "", false, gui["tab_2"]) 
guiEditSetMaxLength(gui["lineEdit"], 32767) 
    
gui["registerButton"] = guiCreateButton(52,105, 131, 23, "Register", false, gui["tab_2"]) 
    
end 
addEventHandler("onClientResourceStart",getRootElement(),drawWindow) 
  
 addEventHandler("onClientGuiClick", gui["registerButton"], 
function on_registerButton_clicked() 
    username = guiGetText(gui["registerUsernameEdit"]) 
    pw = guiGetText(gui["registerPasswordEdit"]) 
    pw2 = guiGetText(gui["registerPasswordEditRepeat"]) 
    outputChatBox(username) 
    outputChatBox(pw) 
    outputChatBox(pw2) 
end 
) 

Posted

Thanks, but still not works.

There's an error message:

ERROR: tg\RegisterLogin.lua:81: attempt to index global 'gui' (a nil value)

Interesting...

UPDATE:

Okay, I modified some parts, and now it's works. If someone wants to check the whole code and the fix, here you go:

function drawWindow() 
    showCursor(true) 
  
    gui = {} 
    gui._placeHolders = {} 
     
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 250, 195 
    local left = screenWidth/2 - windowWidth/2 
    local top = screenHeight/2 - windowHeight/2 
    gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "Login/Register", false) 
    guiWindowSetSizable(gui["_root"], false) 
     
    gui["tabWidget"] = guiCreateTabPanel(0, 20, 251, 181, false, gui["_root"]) 
     
    gui["tab"] = guiCreateTab("Login", gui["tabWidget"]) 
     
    gui["loginButton"] = guiCreateButton(40, 100, 141, 21, "Login", false, gui["tab"]) 
    if on_loginButton_clicked then 
        addEventHandler("onClientGUIClick", gui["loginButton"], on_loginButton_clicked, false) 
    end 
     
    gui["label"] = guiCreateLabel(20, 30, 61, 16, "Username:", false, gui["tab"]) 
    guiLabelSetHorizontalAlign(gui["label"], "left", false) 
    guiLabelSetVerticalAlign(gui["label"], "center") 
     
    gui["label_2"] = guiCreateLabel(20, 60, 51, 16, "Password:", false, gui["tab"]) 
    guiLabelSetHorizontalAlign(gui["label_2"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_2"], "center") 
     
    gui["loginUserNameEdit"] = guiCreateEdit(90, 30, 113, 20, "", false, gui["tab"]) 
    guiEditSetMaxLength(gui["loginUserNameEdit"], 32767) 
     
    gui["loginPasswordEdit"] = guiCreateEdit(90, 60, 113, 20, "", false, gui["tab"]) 
    guiEditSetMaxLength(gui["loginPasswordEdit"], 32767) 
     
    gui["tab_2"] = guiCreateTab("Register", gui["tabWidget"]) 
     
    gui["label_3"] = guiCreateLabel(10, 10, 61, 16, "Username:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_3"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_3"], "center") 
     
    gui["label_4"] = guiCreateLabel(10, 40, 61, 16, "Password:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_4"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_4"], "center") 
     
    gui["label_5"] = guiCreateLabel(10, 70, 91, 16, "Password again:", false, gui["tab_2"]) 
    guiLabelSetHorizontalAlign(gui["label_5"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_5"], "center") 
     
    gui["registerUsernameEdit"] = guiCreateEdit(110, 10, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["registerUsernameEdit"], 32767) 
     
    gui["registerPasswordEdit"] = guiCreateEdit(110, 40, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["registerPasswordEdit"], 32767) 
     
    gui["registerPasswordEditRepeat"] = guiCreateEdit(110, 70, 113, 20, "", false, gui["tab_2"]) 
    guiEditSetMaxLength(gui["registerPasswordEditRepeat"], 32767) 
     
    gui["registerButton"] = guiCreateButton(52,105, 131, 23, "Register", false, gui["tab_2"]) 
    if on_registerButton_clicked then 
        addEventHandler("onClientGUIClick", gui["registerButton"], on_registerButton_clicked,false) 
    end 
     
    return gui, windowWidth, windowHeight     
end 
addEventHandler("onClientResourceStart",getRootElement(),drawWindow) 
  
function on_registerButton_clicked()          
    username = guiGetText(gui["registerUsernameEdit"]) 
    pw = guiGetText(gui["registerPasswordEdit"]) 
    pw2 = guiGetText(gui["registerPasswordEditRepeat"]) 
    outputChatBox(username) 
    outputChatBox(pw) 
    outputChatBox(pw2) 
end 

Thanks iMr.3a[Z]eF for the help.

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