maffius Posted May 27, 2017 Share Posted May 27, 2017 (edited) addCommandHandler("myAccounts", function (player, cmd) local serial = getPlayerSerial(player) local accounts = getAccountsBySerial(serial) outputChatBox("You have " .. #accounts .. " accounts with these logins: ".. table.concat(accounts, ", "), player) end) And it gives error: invalid value (userdata) at index 1 in table for 'concat' How can I make this table to string? Edited May 27, 2017 by maffius Link to comment
pa3ck Posted May 27, 2017 Share Posted May 27, 2017 The table returns accounts, why do you want to output them as string? Even if you make them string they would look like "Userdata: xxxxx" which is no use at all. Do you want to output the account names because that's a different thing. Link to comment
Discord Moderators AlexTMjugador Posted May 27, 2017 Discord Moderators Share Posted May 27, 2017 (edited) 1 hour ago, pa3ck said: Do you want to output the account names because that's a different thing. If that's what you want to do, you'll have to create an intermediate table with the account names as strings on it, and pass that to the table.concat function. table.concat expects a table with strings on its indexes, but does not convert any data in it to a string itself. This code should comply with your needs: addCommandHandler("myAccounts", function (player, cmd) local accounts = getAccountsBySerial(getPlayerSerial(player)) local accountNames = {} local accountNumber = 0 for _, acc in pairs(accounts) do accountNumber = accountNumber + 1 -- Why use the table length operator when you iterate over its elements and can do this? This seems more efficient accountNames[accountNumber] = getAccountName(acc) end outputChatBox("You have " .. accountNumber .. " accounts with these logins: ".. table.concat(accountNames, ", "), player) end ) If you have any doubt of why or how does that work you can add a reply to this post, so someone can help you out Edited May 27, 2017 by AlexTMjugador Optimizations & typos Link to comment
maffius Posted May 27, 2017 Author Share Posted May 27, 2017 Works good, thanks. I dont need any explanation, Im not that nooby as you think 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