Was working on the final and hardest part (for me) of my whitelist addon when I kept getting this same error
[ERROR] addons/whitelistbyzee/lua/autorun/shared.lua:86: bad argument #1 to 'pairs' (table expected, got nil)
1. pairs - [C]:-1
2. func - addons/whitelistbyzee/lua/autorun/shared.lua:86
3. unknown - lua/includes/modules/net.lua:32Line 86 is the one that reads "for k, v in pairs..."
local DL = vgui.Create("DListView", DF)
DL:SetMultiSelect(false)
DL:SetPos(5,50)
DL:SetSize(150, 245)
DL:AddColumn("SteamIDs")
for k, v in pairs( whitelist ) do
DL:AddLine(v)
end
However, I don't believe the issue is there, for before I switched my table over to a data file, that line gave no errors
Instead of the "whitelist" table being defined at the top of the Lua file like I had before, I decided it would be best for me to keep it in a data file named whitelist.txt due to the fact that if I didn't, the idea of editing the list from ingame would be useless since it would reset with every map change/restart
That being said, this is now the code at the top of the file
local uwhitelist = {
"STEAM_0:1:7099", //Garry
"STEAM_0:0:55581053" //The creator of this addon
}
local uaj = util.TableToJSON(uwhitelist) //uaj stands for Uwhitelist As JSON
local cwf = file.Read("whitelist.txt", "DATA") //cwf stands for Current Whitelist File
if (uaj==cwf) then
local whitelist = util.JSONToTable(cwf)
end
util.JSONToTable is supposed to return a table, so I'm not sure why it's not working
PS:
When I commented out the if statement on line 7 and 9 (but leaving line 8 valid), I got a different error that I still don't understand, since file.Read returns a string and whitelist.txt is definitely not empty
[ERROR] addons/whitelistbyzee/lua/autorun/shared.lua:8: bad argument #1 to 'JSONToTable' (string expected, got no value)
1. JSONToTable - [C]:-1
2. unknown - addons/whitelistbyzee/lua/autorun/shared.lua:8Incase you want to know, this is the current state of whitelist.txt
{"1":"STEAM_0:1:7099","2":"STEAM_0:0:55581053"}