R7flOq7KeSsU Posted October 28, 2009 Share Posted October 28, 2009 Okay, now the problem is: I can't create a table for Element "RadarArea" ZoneInfo = {} g_root = getRootElement() function ResourceStart() -- GangZones Setup local ReadZones = executeSQLQuery("SELECT Name, PosX, PosY, Width, Height FROM LSWars_Zones") local Zones = getElementsByType("radararea") ZoneInfo[Zones] = {} ZoneInfo[Zones].Name = "" for k,v in pairs(ReadZones) do createRadarArea(v.PosX, v.PosY, v.Width, v.Height, 255, 255, 255, 150) for i,z in pairs(Zones) do ZoneInfo[z].Name = v.Name end end end addEventHandler("onResourceStart", g_root, ResourceStart) So far this seems to be okay... but... function GetStats(player) local Zones = getElementsByType("radararea") --[[>>> LINE 186 <<<< --]]for k,v in pairs(Zones) do if(ZoneInfo[v].Name) then outputChatBox("Zone name: " .. ZoneInfo[v].Name .. " Zone ID: " .. k, player) end end end addCommandHandler("stats", GetStats) When I type the commad it gives a server error: ERROR: ...s/server/mods/deathmatch/resources/lswars/lswars.lua:186: attempt to index field '?' (a nil value) Link to comment
50p Posted October 28, 2009 Share Posted October 28, 2009 You can't get that error message on this line, probably the next one. People should start to learn to debug scripts themselves. getElementsByType returns indexed table of elements. These elements are not tables so ZoneInfo[v].Name is invalid! 1. ZoneInfo[ v ] == nil (it's nil because v is element ZoneInfo is (number) indexed table therefore it's invalid) 2. ZoneInfo[ v ].Name == nil (because ZoneInfo[ v ] == nil, you can't get elements out of nil) 3. v ~= table (v is not table, even v.Name will be invalid) Solution: if ( getElementData( v, "Name" ) then -- your outputChatBox.... here end 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