1LoL1 Posted February 24, 2016 Posted February 24, 2016 (edited) Hello, can anyone help me why i have this error? ERROR: attempt to index local 'q' (a userdata value) function whenPlayerChangeNick(_, newNick) local newNick = removeHexColorCode(newNick) local serial = getPlayerSerial(source) local q = dbQuery(database,"SELECT * FROM Nick WHERE Serial = ?", serial) local poll, rows = dbPoll(q, -1) if (rows == 1) then local actualNicks = q["Nicks"].nicks if string.find(actualNicks, newNick) then else local addNewNick = actualNicks .. ", " .. newNick dbExec(database, "UPDATE Nick SET Nicks = ? WHERE Serial = ?", addNewNick, serial) end end end addEventHandler("onPlayerChangeNick", getRootElement(), whenPlayerChangeNick) Edited February 24, 2016 by Guest
1LoL1 Posted February 24, 2016 Author Posted February 24, 2016 local actualNicks = poll["Nicks"] Not work. ERROR: bad argument #1 to 'find' (string expected, got nil)
KariiiM Posted February 24, 2016 Posted February 24, 2016 Try that, function whenPlayerChangeNick(_, newNick) local newNick = removeHexColorCode(newNick) local serial = getPlayerSerial(source) local q = dbQuery(database,"SELECT * FROM Nick WHERE Serial = ?", serial) local result = dbPoll(q, -1) if (result) then local actualNicks = q["Nicks"].nicks if string.find(actualNicks, newNick) then else local addNewNick = actualNicks .. ", " .. newNick dbExec(database, "UPDATE Nick SET Nicks = ? WHERE Serial = ?", addNewNick, serial) end else dbExec(database, "INSERT INTO Nick VALUES(?,?)", addNewNick, serial) end end addEventHandler("onPlayerChangeNick", getRootElement(), whenPlayerChangeNick)
SpecT Posted February 24, 2016 Posted February 24, 2016 function whenPlayerChangeNick(_, newNick) local newNick = removeHexColorCode(newNick) local serial = getPlayerSerial(source) local q = dbQuery(database,"SELECT * FROM Nick WHERE Serial = ?", serial) local result = dbPoll(q, -1) if (result) then local actualNicks = poll["Nicks"] if string.find(actualNicks, newNick) then else local addNewNick = actualNicks .. ", " .. newNick dbExec(database, "UPDATE Nick SET Nicks = ? WHERE Serial = ?", addNewNick, serial) end else dbExec(database, "INSERT INTO Nick VALUES(?,?)", addNewNick, serial) end end addEventHandler("onPlayerChangeNick", getRootElement(), whenPlayerChangeNick)
1LoL1 Posted February 24, 2016 Author Posted February 24, 2016 function whenPlayerChangeNick(_, newNick) local newNick = removeHexColorCode(newNick) local serial = getPlayerSerial(source) local q = dbQuery(database,"SELECT * FROM Nick WHERE Serial = ?", serial) local result = dbPoll(q, -1) if (result) then local actualNicks = poll["Nicks"] if string.find(actualNicks, newNick) then else local addNewNick = actualNicks .. ", " .. newNick dbExec(database, "UPDATE Nick SET Nicks = ? WHERE Serial = ?", addNewNick, serial) end else dbExec(database, "INSERT INTO Nick VALUES(?,?)", addNewNick, serial) end end addEventHandler("onPlayerChangeNick", getRootElement(), whenPlayerChangeNick) It's fixed.. and poll["Nicks"] ? where is poll?
SpecT Posted February 24, 2016 Posted February 24, 2016 Sorry, I posted it before I see you solved it and my bad ... its result["Nicks"] I didn't notice that the variable name is changed. Anyway, good luck with whatever you are working on!
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