eniallator

Scanner Client Program

Jun 14th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. rednet.open("back")
  2. idsToCheck = {}
  3. -- list of ids to check and update from
  4.  
  5. tArgs = { ... }
  6. local newFileContents = ""
  7. local overwrite = false
  8.  
  9. if tArgs[1] then
  10.   if fs.exists(tArgs[1]) then
  11.  
  12.     print("File exists. Overwrite? (Y/N)")
  13.     answer = read()
  14.  
  15.     if answer:lower() == "y" then
  16.  
  17.       overwrite = true
  18.     end
  19.   end
  20.  
  21.   if not fs.exists(tArgs[1]) or overwrite then
  22.     for i=1,#idsToCheck do
  23.  
  24.       rednet.send(idsToCheck[i],"sendScan")
  25.       local currID = -1
  26.  
  27.       while currID ~= idsToCheck[i] do
  28.  
  29.         currID,msg = rednet.receive(0.1)
  30.         if not currID then break end
  31.       end
  32.  
  33.       if currID then
  34.  
  35.         spacing = "\n\n\n"
  36.         if newFileContents == "" then spacing = "" end
  37.  
  38.         newFileContents = newFileContents .. spacing ..  "Log for ID: " .. currID .. "\n" .. msg
  39.       end
  40.     end
  41.  
  42.     logFile = fs.open(tArgs[1],"w")
  43.     logFile.write(newFileContents)
  44.     logFile.close()
  45.   end
  46.  
  47. else
  48.   print("Invalid arguments. Give file output as first argument.")
  49. end
Advertisement
Add Comment
Please, Sign In to add comment