Simi23 Posted July 20, 2017 Share Posted July 20, 2017 Hello! I have made closely an entire faction-system, but i have problems with loops. This client side script is for put the faction members and their properties in one table. menuPlayers = {} for i = 1, #memberUsernames do menuPlayers[i].name = memberUsernames[i] menuPlayers[i].rank = memberRanks[i] menuPlayers[i].status = memberOnline[i] menuPlayers[i].lastlogin = memberLastLogin[i] menuPlayers[i].active = 0 end when i do it like this ^^ i got this error for the rows in the loop: attempt to index field '?' (a nil value) But, when i remove the loop and try it for only the first player, it works: menuPlayers = {} menuPlayers[1].name = memberUsernames[1] menuPlayers[1].rank = memberRanks[1] menuPlayers[1].status = memberOnline[1] menuPlayers[1].lastlogin = memberLastLogin[1] menuPlayers[1].active = 0 Any help? Thanks. Link to comment
Tails Posted July 20, 2017 Share Posted July 20, 2017 It means one or more keys don't exist in one of your tables. I can't tell you which one unless you show you us how your tables look like. Link to comment
Simi23 Posted July 20, 2017 Author Share Posted July 20, 2017 (edited) memberUsernames is a table with all the usernames of the members eg {William Johns, Sergej Platnikov, Feliks Anyukov, Frank Williams, etc.} memberRanks is a table, with the ranks of the members eg: {1, 4, 14, 3, 7, 5, etc.} memberOnline is a table, with the statuses of the members eg: {true, false, false, true, true, etc.} (true means online, false means offline) memberLastlogin is a table, with the last logins of the members eg: {today, yesterday, today, 4 days ago, 2 weeks ago, etc.} active can be 0 or 1 as a default, everyone has 0. Another loop sets the first 15 member to active, so the rendering part will know which members must be rendered. If the user scrolls down, the first member who has 1, will be set to 0. The first member who have 0 after a member who have 1, will set to 1. Do I want to use table.insert? When i do the loop, its not really showing the error to every row at once, only for the first. But if i remove the first row, the error will appear at the second, and so on. Edited July 20, 2017 by Simi23 Clarification. Link to comment
pa3ck Posted July 20, 2017 Share Posted July 20, 2017 menuPlayers = {} for i = 1, #memberUsernames do menuPlayers[i] = {} menuPlayers[i].name = memberUsernames[i] menuPlayers[i].rank = memberRanks[i] menuPlayers[i].status = memberOnline[i] menuPlayers[i].lastlogin = memberLastLogin[i] menuPlayers[i].active = 0 end Try this 1 Link to comment
Simi23 Posted July 20, 2017 Author Share Posted July 20, 2017 It's WORKING !!! Thank you so much! Link to comment
pa3ck Posted July 20, 2017 Share Posted July 20, 2017 (edited) You're welcome. The problem was that you treated menuPlayers[ i ] as if it was a table already, but it wasn't. Edited July 20, 2017 by pa3ck 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