Matevsz Posted June 4, 2016 Share Posted June 4, 2016 login, password = LoginFromXML() if not (login == "" or password == "") then guiCheckBoxGetSelected(save_account, true) guiSetText(edit_login, tostring(login)) guiSetText(edit_haslo, tostring(password)) else guiCheckBoxGetSelected(save_account, false) guiSetText(edit_login, tostring(login)) guiSetText(edit_haslo, tostring(password)) end end function LoginFromXML() local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") if not xml_save_log_File then xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") end local usernameNode = xmlFindChild (xml_save_log_File, "login", 0) local passwordNode = xmlFindChild (xml_save_log_File, "password", 0) if usernameNode and passwordNode then return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode) else return "", "" end xmlUnloadFile ( xml_save_log_File ) end DB3: attempt to call global 'LoginFromXML a nil value Link to comment
WhoAmI Posted June 4, 2016 Share Posted June 4, 2016 put LoginFromXML function before login,password variables. Link to comment
nxFairlywell Posted June 4, 2016 Share Posted June 4, 2016 function LoginFromXML() local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") if not xml_save_log_File then xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") end local usernameNode = xmlFindChild (xml_save_log_File, "login", 0) local passwordNode = xmlFindChild (xml_save_log_File, "password", 0) if usernameNode and passwordNode then return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode) else return "", "" end xmlUnloadFile ( xml_save_log_File ) end login, password = LoginFromXML() if not (login == "" or password == "") then guiCheckBoxGetSelected(save_account, true) guiSetText(edit_login, tostring(login)) guiSetText(edit_haslo, tostring(password)) else guiCheckBoxGetSelected(save_account, false) guiSetText(edit_login, tostring(login)) guiSetText(edit_haslo, tostring(password)) end Link to comment
Matevsz Posted June 4, 2016 Author Share Posted June 4, 2016 and how to make checking the field username and password field are not empty? editLogin = guiCreateEdit(1246, 417, 237, 34, "", false) editPassword = guiCreateEdit(1246, 468, 237, 34, "", false) guiEditSetMasked(editPassword, true) Link to comment
WhoAmI Posted June 4, 2016 Share Posted June 4, 2016 if guiGetText(editLogin) ~= "" and guiGetText(editPassword) ~= "" then --not empty end Link to comment
Matevsz Posted June 4, 2016 Author Share Posted June 4, 2016 Help 0 Errors and 0 errors in db3 Client: wdwLogin_Pannel = {} function OpenLoginPanel() if not (isElement(wdwLogin_Pannel)) then showChat(false) showCursor(true) x,y = guiGetScreenSize() local sWidth, sHeight = guiGetScreenSize() local Width, Height = 1680, 1050 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) --login tlo = guiCreateStaticImage(0, 0, 1680, 1050, "Zdjecia/background.jpg", false) guiSetEnabled(tlo, false) errorLogin = guiCreateLabel(1187, 550, 475, 15, "", false) guiLabelSetColor(errorLogin, 227, 0, 0) zapamietajKonto = guiCreateCheckBox(1246, 516, 199, 16, "Zapamiętaj konto", true, false) guiCheckBoxSetSelected(zapamietajKonto, false) polelogin = guiCreateEdit(1246, 417, 237, 34, "", false) gridlist = guiCreateGridList(24, 83, 93, 113, false, polelogin) polehaslo = guiCreateEdit(1246, 468, 237, 34, "", false) guiEditSetMasked(polehaslo, true) zdj = guiCreateStaticImage(1195, 419, 33, 32, "Zdjecia/person.png", false) zdj2 = guiCreateStaticImage(1194, 468, 34, 34, "Zdjecia/password.png", false) zdj3 = guiCreateStaticImage(1501, 407, 106, 51, "Zdjecia/login.png", false) zdj4 = guiCreateStaticImage(1501, 458, 108, 54, "Zdjecia/register.png", false) --rejestracja tloReje = guiCreateStaticImage(0, 0, 1680, 1050, "Zdjecia/background2.jpg", false) guiSetVisible(tloReje, false) guiSetEnabled(tloReje, false) errorReje = guiCreateLabel(1200, 571, 460, 15, "", false) guiLabelSetColor(errorReje, 227, 0, 0) guiSetVisible(errorReje, false) poleLoginReje = guiCreateEdit(1246, 417, 237, 34, "", false) guiSetVisible(poleLoginReje, false) gridlistReje = guiCreateGridList(24, 83, 93, 113, false, poleLoginReje) guiSetVisible(gridlistReje, false) poleHasloReje = guiCreateEdit(1246, 468, 237, 34, "", false) guiEditSetMasked(poleHasloReje, true) guiSetVisible(poleHasloReje, false) poleHasloReje2 = guiCreateEdit(1246, 517, 237, 34, "", false) guiEditSetMasked(poleHasloReje2, true) guiSetVisible(poleHasloReje2, false) zdjReje = guiCreateStaticImage(1195, 419, 33, 32, "Zdjecia/person.png", false) guiSetVisible(zdjReje, false) zdjReje2 = guiCreateStaticImage(1194, 468, 34, 34, "Zdjecia/password.png", false) guiSetVisible(zdjReje2, false) zdjReje3 = guiCreateStaticImage(1194, 517, 34, 34, "Zdjecia/password.png", false) guiSetVisible(zdjReje3, false) zdjReje4 = guiCreateStaticImage(1499, 406, 115, 55, "Zdjecia/konto.png", false) guiSetVisible(zdjReje4, false) zdjReje5 = guiCreateStaticImage(1496, 467, 118, 54, "Zdjecia/sh.png", false) guiSetVisible(zdjReje5, false) guiSetText(errorLogin, "") guiSetText(errorReje, "") function LoginFromXML() local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") if not xml_save_log_File then xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") end local usernameNode = xmlFindChild (xml_save_log_File, "login", 0) local passwordNode = xmlFindChild (xml_save_log_File, "haslo", 0) if usernameNode and passwordNode then return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode) else return "", "" end xmlUnloadFile ( xml_save_log_File ) end login, haslo = LoginFromXML() if not (login == "" or haslo == "") then guiCheckBoxGetSelected(zapamietajKonto, true) guiSetText(polelogin, tostring(login)) guiSetText(polehaslo, tostring(haslo)) else guiCheckBoxGetSelected(zapamietajKonto, false) guiSetText(polelogin, tostring(login)) guiSetText(polehaslo, tostring(haslo)) end end function PokazReje() guiSetVisible(tlo, false) guiSetVisible(errorLogin, false) guiSetVisible(zapamietajKonto, false) guiSetVisible(polelogin, false) guiSetVisible(gridlist, false) guiSetVisible(polehaslo, false) guiSetVisible(zdj, false) guiSetVisible(zdj2, false) guiSetVisible(zdj3, false) guiSetVisible(zdj4, false) guiSetVisible(tloReje, true) guiSetVisible(errorReje, true) guiSetVisible(poleLoginReje, true) guiSetVisible(gridlistReje, true) guiSetVisible(poleHasloReje, true) guiSetVisible(poleHasloReje2, true) guiSetVisible(zdjReje, true) guiSetVisible(zdjReje2, true) guiSetVisible(zdjReje3, true) guiSetVisible(zdjReje4, true) guiSetVisible(zdjReje5, true) end addEventHandler("onClientGUIClick", zdj4, PokazReje) function Wroc() guiSetVisible(tlo, true) guiSetVisible(errorLogin, true) guiSetVisible(zapamietajKonto, true) guiSetVisible(polelogin, true) guiSetVisible(gridlist, true) guiSetVisible(polehaslo, true) guiSetVisible(zdj, true) guiSetVisible(zdj2, true) guiSetVisible(zdj3, true) guiSetVisible(zdj4, true) guiSetVisible(tloReje, false) guiSetVisible(errorReje, false) guiSetVisible(poleLoginReje, false) guiSetVisible(gridlistReje, false) guiSetVisible(poleHasloReje, false) guiSetVisible(poleHasloReje2, false) guiSetVisible(zdjReje, false) guiSetVisible(zdjReje2, false) guiSetVisible(zdjReje3, false) guiSetVisible(zdjReje4, false) guiSetVisible(zdjReje5, false) end addEventHandler("onClientGUIClick", zdjReje5, Wroc) function Zaloguj(button,state) showCursor(false) showChat(true) guiSetVisible(tlo, false) guiSetVisible(errorLogin, false) guiSetVisible(zapamietajKonto, false) guiSetVisible(polelogin, false) guiSetVisible(gridlist, false) guiSetVisible(polehaslo, false) guiSetVisible(zdj, false) guiSetVisible(zdj2, false) guiSetVisible(zdj3, false) guiSetVisible(zdj4, false) if (button == "left" and state == "up") then if guiGetText(polelogin) ~= "" and guiGetText(polehaslo) ~= "" then if (source == zdjReje5) then login = guiGetText(polelogin) haslo = guiGetText(polehaslo) if guiCheckBoxGetSelected(zapamietajKonto) == true then checksave = true else checksave = false end triggerServerEvent("onRequestLogin", getLocalPlayer(), login, haslo, checksave) end end end end addEventHandler("onClientGUIClick", zdj3, Zaloguj) function StworzKonto(button,state) login = guiGetText(poleLoginReje) haslo = guiGetText(poleHasloReje) potwierdzHaslo = guiGetText(poleHasloReje2) triggerServerEvent("onRequestLogin", getLocalPlayer(), login, haslo, potwierdzHaslo) guiSetText(errorReje, "Konto stworzone pomyślnie. Możesz się zalogować.") setTimer(function() guiSetText(errorReje, "") end,3000,1) setTimer(function() guiSetText(errorReje, "") end,3000,1) end addEventHandler("onClientGUIClick", zdjReje4, StworzKonto) function Errory(Tab, Text) if Tab == "Login" then guiSetVisible(tlo, true) guiSetVisible(errorLogin, true) guiSetVisible(zapamietajKonto, true) guiSetVisible(polelogin, true) guiSetVisible(gridlist, true) guiSetVisible(polehaslo, true) guiSetVisible(zdj, true) guiSetVisible(zdj2, true) guiSetVisible(zdj3, true) guiSetVisible(zdj4, true) guiSetText(errorLogin, tostring(Text)) setTimer(function() guiSetText(errorLogin, "") end,3000,1) elseif Tab == "Haslo" then guiSetText(errorReje, tostring(Text)) setTimer(function() guiSetText(errorReje, "") end,3000,1) end end addEvent("RozneErrory", true) addEventHandler("RozneErrory", getRootElement(), Errory) function saveLoginToXML(login, haslo) local xml_save_log_File = xmlLoadFile ("files/xml/userdata.xml") if not xml_save_log_File then xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login") end if (login ~= "") then local usernameNode = xmlFindChild (xml_save_log_File, "login", 0) if not usernameNode then usernameNode = xmlCreateChild(xml_save_log_File, "login") end xmlNodeSetValue (usernameNode, tostring(login)) end if (haslo ~= "") then local passwordNode = xmlFindChild (xml_save_log_File, "haslo", 0) if not passwordNode then passwordNode = xmlCreateChild(xml_save_log_File, "haslo") end xmlNodeSetValue (passwordNode, tostring(haslo)) end 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