diff --git a/netNav_goto b/netNav_goto index 2963a2c..7a15242 100644 --- a/netNav_goto +++ b/netNav_goto @@ -1,3 +1,10 @@ +local function printUsage() + print("Usage:") + print(fs.getName(shell.getRunningProgram()).." ") + print(" The name of the remoteMap to connect to and use.") + print(" The GPS coordinates you want to go to.") +end + if not netNav then if not os.loadAPI("netNav") then error("could not load netNav API") @@ -10,18 +17,33 @@ for _, side in ipairs(redstone.getSides()) do end end -netNav.setMap("main", 30) - +if not rednet.isOpen() then + error("could not open rednet") +end + local tArgs = {...} -if #tArgs == 3 then - for i = 1, #tArgs do - if tonumber(tArgs[i]) then - tArgs[i] = tonumber(tArgs[i]) - else - error("argument "..i.." must be a valid coordinate") - end + +if type(tArgs[1]) ~= "string" then + printError("remoteMap_name: string expected") + printUsage() + return +end +netNav.setMap(tArgs[1], 30) + +for i = 2, 4 do + if tonumber(tArgs[i]) then + tArgs[i] = tonumber(tArgs[i]) + else + printError("argument "..i.." must be a valid coordinate") + printUsage() + return end - print(netNav.goto(tArgs[1], tArgs[2], tArgs[3])) +end + +print("going to coordinates = ", tArgs[2], ",", tArgs[3], ",", tArgs[4]) +local ok, err = netNav.goto(tArgs[2], tArgs[3], tArgs[4]) +if not ok then + printError("navigation failed: ", err) else - error("arguments must be 3 or 4 numbers") + print("succesfully navigated to coordinates") end \ No newline at end of file diff --git a/starNav_goto b/starNav_goto index a088c6d..ca15b93 100644 --- a/starNav_goto +++ b/starNav_goto @@ -1,3 +1,11 @@ +local function printUsage() + print("Usage:") + print(fs.getName(shell.getRunningProgram()).." <(optional)max_distance>") + print(" The name of the remoteMap to connect to and use.") + print(" The GPS coordinates you want to go to.") + print("<(optional)max_distance> The farthest distance allowed to travel from start position.") +end + if not starNav then if not os.loadAPI("starNav") then error("could not load starNav API") @@ -5,15 +13,40 @@ if not starNav then end local tArgs = {...} -if #tArgs == 3 or #tArgs == 4 then - for i = 1, #tArgs do - if tonumber(tArgs[i]) then - tArgs[i] = tonumber(tArgs[i]) - else - error("argument "..i.." must be a valid coordinate") - end + +if type(tArgs[1]) ~= "string" then + printError("map_name: string expected") + printUsage() + return +end +starNav.setMap(tArgs[1]) + +for i = 2, 4 do + if tonumber(tArgs[i]) then + tArgs[i] = tonumber(tArgs[i]) + else + printError("argument "..i.." must be a valid coordinate") + printUsage() + return end - print(starNav.goto(tArgs[1], tArgs[2], tArgs[3], tArgs[4])) +end + +local maxDistance +if tArgs[5] ~= nil then + if tonumber(tArgs[5]) then + print("setting max_distance to: ", tArgs[5]) + maxDistance = tonumber(tArgs[5]) + else + printError("max_distance: number expected") + printUsage() + return + end +end + +print("going to coordinates = ", tArgs[2], ",", tArgs[3], ",", tArgs[4]) +local ok, err = starNav.goto(tArgs[2], tArgs[3], tArgs[4], maxDistance) +if not ok then + printError("navigation failed: ", err) else - error("arguments must be 3 or 4 numbers") + print("succesfully navigated to coordinates") end \ No newline at end of file