Posted 27 June 2014 - 11:49 PM
Hey guys, for some reason x y and z values aren't being detected in my code. I probably did something stupid but I can't seem to figure it out.
And before you say it, I know the table exists and is being downloaded everytime.
All I want it to do is tell me which tower is the closest, so if you have an easier way of doing that than please tell me!
Error: sgps:17: attempt to perform arithmetic __add on nil and nil
http://pastebin.com/K1WyPcKc
http://pastebin.com/MCCNBq1a
And before you say it, I know the table exists and is being downloaded everytime.
All I want it to do is tell me which tower is the closest, so if you have an easier way of doing that than please tell me!
Error: sgps:17: attempt to perform arithmetic __add on nil and nil
http://pastebin.com/K1WyPcKc
--UPDATE SGPS
local towerdata = http.get("http://pastebin.com/raw.php?i=MCCNBq1a").readAll()
local fl = fs.open("data/twrs", "w")
fl.write(towerdata)
fl.close()
local h = fs.open("data/twrs", "r")
towers = h.readAll()
fl.close()
--END UPDATE SGPS
args = {...}
local towerstable = textutils.unserialize(towers)
local function getClosestTower()
local twrst = {}
local twrsn = {}
for k,v in pairs(towerstable) do
local t = v[x]+v[y]+v[z]
table.insert(twrst, k)
table.insert(twrsn, t)
end
local num = math.max(unpack(twrsn))
local name = ""
for k,v in pairs(items) do
if(v==num) then
name = k
end
end
return name
end
if args[1] == "locate" then
local loc = gps.locate()
--local loctext = loc[1]..", "..loc[2]..", "..loc[3]
--print("You are at: "..loctext..".")
print("Your closest tower is: "..getClosestTower())
end
http://pastebin.com/MCCNBq1a
{
["XiTech Tower 1"] = {x=-149,y=227,z=-24},
["Sertex #1"] = {x=74,y=224,z=-29},
["Sertex #2"] = {x=62,y=227,z=-111},
["Sertex #2"] = {x=62,y=227,z=-105},
["Sertex #3"] = {x=71,y=227,z=-26}
}