Tomc0 Posted July 28, 2013 Share Posted July 28, 2013 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. Link to comment
iMr.3a[Z]eF Posted July 28, 2013 Share Posted July 28, 2013 Write in the console debugscript 3, and tell us what is it output. Link to comment
Tomc0 Posted July 28, 2013 Author Share Posted July 28, 2013 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. Link to comment
iMr.3a[Z]eF Posted July 28, 2013 Share Posted July 28, 2013 OK, after fixing that, what is output? Link to comment
Tomc0 Posted July 28, 2013 Author Share Posted July 28, 2013 Nothing, just an info: votemanager precreateGuiElements. Link to comment
iMr.3a[Z]eF Posted July 28, 2013 Share Posted July 28, 2013 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 ) Link to comment
Tomc0 Posted July 28, 2013 Author Share Posted July 28, 2013 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. 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