This bit of code works great on my listen server but when I try it on my dedicated I get this error:
[Error] Line 17: Attempt to compare number with nil.
[lua]
local MapList = file.Read("ttt/MapCoolDownList.txt", "DATA")
local MapList_TableForm = util.JSONToTable( MapList )
local function AddMaps()
if ( !file.IsDir( "ttt", "DATA" ) ) then file.CreateDir( "ttt" ) end
local CurrentMap = game.GetMap()
if !table.HasValue(MapList_TableForm,CurrentMap) then
table.insert(MapList_TableForm,1,CurrentMap)
end
file.Write( "ttt/MapCoolDownList.txt", util.TableToJSON( MapList_TableForm ) )
if table.GetLastKey(MapList_TableForm) >= 6 then --This line throws an error
table.remove(MapList_TableForm, 6 )
file.Write( "ttt/MapCoolDownList.txt", util.TableToJSON( MapList_TableForm ) )
end
end
hook.Add("Initialize", "AddMapstoCooldownList", AddMaps )
[/lua]
Did you even bother reading your error? Your "table.GetLastKey( MapList_TableForm )" is returning nil and you can't compare nothing with a number.
[QUOTE=EvacX;43010641]Did you even bother reading your error? Your "table.GetLastKey( MapList_TableForm )" is returning nil and you can't compare nothing with a number.[/QUOTE]
Why don't we just avoid the counter productive responses. I don't need you to elaborate on the error, I understand the error just fine. What I don't understand is why it's throwing an error on a dedicated and not a listen server.
[editline]28th November 2013[/editline]
Thanks for the fix z-machine!
Replaced the broken line with:
[lua]
if ( table.GetLastKey(MapList_TableForm) or 6 ) then
[/lua]
Sorry, you need to Log In to post a reply to this thread.