Ziemo Posted August 7, 2019 Posted August 7, 2019 Hi, I've started writing scripts connected to the database, and I struggle why the current script that I am working on doesn't work. Info: - Name of the table: accounts - Columns: username, skin, money - No errors Here is my script: function showStats(player) local playerName = getPlayerName(player) local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName) local result = dbPoll(qh, -1) if result then for _, row in ipairs(result) do outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "") end end end addCommandHandler("stats", showStats)
DNL291 Posted August 7, 2019 Posted August 7, 2019 Are you sure username is the player name and not the account name? @Ziemo Please do not PM me with scripting related question nor support, use the forums instead.
Ziemo Posted August 7, 2019 Author Posted August 7, 2019 @DNL291 I have set player's name in mta to the same as in database
DNL291 Posted August 7, 2019 Posted August 7, 2019 Do a test with this code: function showStats(player) local playerName = getPlayerName(player) local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName) local result = dbPoll(qh, -1) if result then for _, row in ipairs(result) do outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "") end end iprint( "qh " .. qh ..", result: ".. result ) end addCommandHandler("stats", showStats) Also, post the code where you create the table and save these values if possible. 1 Please do not PM me with scripting related question nor support, use the forums instead.
Ziemo Posted August 7, 2019 Author Posted August 7, 2019 It works, It outputted valid values, but I see an error: attempt to concatenate local 'result' (a table value)
DNL291 Posted August 7, 2019 Posted August 7, 2019 Try: function showStats(player) local playerName = getPlayerName(player) local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName) local result = dbPoll(qh, -1) if result then result = result[1] for _, row in ipairs(result) do outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "") end end end addCommandHandler("stats", showStats) @Ziemo 1 Please do not PM me with scripting related question nor support, use the forums instead.
Ziemo Posted August 7, 2019 Author Posted August 7, 2019 (edited) This new function doesn't work, but when I delete: iprint( "qh " .. qh ..", result: ".. result ) from the older code, error doesn't show up EDIT: never mind it showed, I just missed it Edited August 7, 2019 by Ziemo
Moderators IIYAMA Posted August 7, 2019 Moderators Posted August 7, 2019 Concat with iprint like this: iprint( "qh ", qh, ", result: ", result ) @Ziemo 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Ziemo Posted August 7, 2019 Author Posted August 7, 2019 It works, shows the info in debug, and outputs skin and money from database! Thanks you both guys. 1
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