Advertisement
Guest User

startup

a guest
May 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -----------------------------------------
  2. --storage check system ver1.0
  3.  
  4. ----------------setting--------------------
  5. os.loadAPI("logging")
  6. receiverComputerID = 2
  7. suckDirecton = turtle.suckUp
  8. shelfX = 6
  9. shelfY = 2
  10.  
  11.  
  12. ----------------function-------------------
  13. function refAll(suckDirecton)
  14.   while turtle.getFuelLevel() < 200 do
  15.     suckDirecton()
  16.     turtle.refuel()
  17.     LP.sendMessage(receiverComputerID,-1)
  18.     os.sleep(2)
  19.   end
  20. end
  21. LC = 0
  22. filledLC = 0
  23. function rsDetect()
  24.   for i=1,4 do
  25.     logging.turnLeft()
  26.     boolean,data = turtle.inspect()
  27.     if boolean then
  28.       if string.find(data.name,"Tra") ==12 then
  29.         if redstone.getInput("front") then
  30.            filledLC = filledLC + 1
  31.         end
  32.         LC = LC +1
  33.       end
  34.     end
  35.   end
  36. end
  37.  
  38. function sweep(shelfX,shelfY)
  39.   for y=1,shelfY do
  40.     for x=1,shelfX do
  41.       logging.forward()
  42.       rsDetect()
  43.     end
  44.     logging.down()
  45.     rsDetect()
  46.     logging.turnLeft()
  47.     logging.turnLeft()
  48.   end
  49.   if shelfY/2 ~= 0 then
  50.    for y=1,shelfY do
  51.       logging.up()
  52.     end
  53.   else
  54.     logging.up()
  55.     for x=1,shelfX do
  56.       logging.forward()
  57.     end
  58.   end
  59. end
  60.  
  61. ------------------main----------------------
  62. if fs.exists(logging.LOG_FILE) then
  63.   term.write("Return to home position..")
  64.   logging.makeRevFile()
  65.   logging.backupFile(logging.LOG_FILE)
  66.   logging.backupFile(logging.REV_FILE)
  67.   shell.run(logging.REV_FILE.."-bak")
  68.   print("ok")
  69. end
  70.  
  71. for k, v in pairs(peripheral.getNames()) do
  72.     if string.find(peripheral.getType(v),"Logi") == 1 then
  73.        LP = peripheral.wrap(v)
  74.     end
  75. end
  76.  
  77. while true do
  78.     LC,filledLC = 0,0
  79.     refAll(suckDirecton)
  80.     sweep(shelfX,shelfY)
  81.     inf = filledLC*1000+LC/1000
  82.     LP.sendMessage(receiverComputerID,inf)
  83.     fs.delete("mylog")
  84.     sleep(5)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement