But if I do the inside my API I'll receive "myapi:78: attempt to index ? (a nil value)"
What am I doing wrong or is there another way doing that in an API?
function startgps()
local x, y, z = myapi.getCoords()
shell.run("gps host "..x.. " "..y.." "..z)
end
function getExitEvent()
while not (os.pullEvent() == "STOP_GPS_NOW") do end
end
do
parallel.waitForAny(startgps, getExitEvent)
end
local function startShell()
if term.isColour() then
os.run( {}, "rom/programs/advanced/multishell" )
else
os.run( {}, "rom/programs/shell" )
end
os.run( {}, "rom/programs/shutdown" )
end
local function gpsServer()
-- Act as a GPS host
if pocket then
print( "GPS Hosts must be stationary" )
return
end
-- Find a modem
local sModemSide = nil
for n,sSide in ipairs( rs.getSides() ) do
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
sModemSide = sSide
break
end
end
if sModemSide == nil then
print( "No wireless modems found. 1 required." )
return
end
-- Open a channel
local modem = peripheral.wrap( sModemSide )
print( "Opening channel on modem "..sModemSide )
modem.open( gps.CHANNEL_GPS )
-- Serve requests indefinitely
while true do
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
if e == "modem_message" then
-- We received a message from a modem
local sSide, sChannel, sReplyChannel, sMessage, nDistance = p1, p2, p3, p4, p5
if sSide == sModemSide and sChannel == gps.CHANNEL_GPS and sMessage == "PING" then
-- We received a ping message on the GPS channel, send a response
modem.transmit( sReplyChannel, gps.CHANNEL_GPS, { x, y, z } )
end
end
end
-- Close the channel
print( "Closing channel" )
modem.close( gps.CHANNEL_GPS )
end
do
parallel.waitForAll(gpsServer, startShell)
end