Merge pull request #181 from SquidDev-CC/hotfix/gps-locate

Ensure GPS coordinates are numbers
This commit is contained in:
Daniel Ratcliffe 2017-05-04 21:02:36 +01:00 committed by GitHub
commit df1ef7133d
2 changed files with 4 additions and 4 deletions

View File

@ -103,7 +103,7 @@ function locate( _nTimeout, _bDebug )
local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5
if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then
-- Received the correct message from the correct modem: use it to determine position
if type(tMessage) == "table" and #tMessage == 3 then
if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then
local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance }
if _bDebug then
print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) )

View File

@ -76,9 +76,9 @@ local vmetatable = {
function new( x, y, z )
local v = {
x = x or 0,
y = y or 0,
z = z or 0
x = tonumber(x) or 0,
y = tonumber(y) or 0,
z = tonumber(z) or 0
}
setmetatable( v, vmetatable )
return v