Posted 22 September 2012 - 04:55 PM
Calling gps.locate() errors" gps:69: attemp to compare nil with number", however if you call gps.locate(1) it functions as normal.
How to reproduce: call gps.locate() without the timeout specified
A quick peek in the code shows us whats wrong
A solution could be:
How to reproduce: call gps.locate() without the timeout specified
A quick peek in the code shows us whats wrong
function locate( _nTimeout, _bDebug )
if _bDebug then
print( "Finding position..." )
end
rednet.broadcast( "PING" )
local startTime = os.clock()
local timeOut = _nTimeout -- set timeOut to nil if nothing is specified
local timeElapsed = 0
local tFixes = {}
local p1, p2 = nil
while timeElapsed < timeOut and (p1 == nil or p2 ~= nil) do -- here we try to compare, and lua errors
A solution could be:
function locate( _nTimeout, _bDebug )
if _bDebug then
print( "Finding position..." )
end
rednet.broadcast( "PING" )
local startTime = os.clock()
if _nTimeout ~= nil then --checking if _nTimeout isn't nil
local timeOut = _nTimeout -- if it is not nil then set timeOut to _nTimeout
else
local timeOut = 1 -- else set timeOut to a default value
end
local timeElapsed = 0
local tFixes = {}
local p1, p2 = nil
while timeElapsed < timeOut and (p1 == nil or p2 ~= nil) do -- no error