Bonkie

Computercraft Turtle Main Program

Apr 2nd, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. args={...}
  2.  
  3. numWells = 16
  4. if (args[1]==nil) then
  5. numRuns = 4
  6. else
  7. numRuns = args[1]
  8. end
  9. shell.run("send99","file","emptyINV")
  10. shell.run("send99","file","wellPlace")
  11. shell.run("send99","file","wellGet")
  12.  
  13. print("Starting mining program.")
  14.  
  15. local m = peripheral.wrap("right")
  16. m.open(100)
  17.  
  18. function advsleep(t)
  19.   for i=1,t do
  20.   print("Sleeping for: ".. t-i .." sec.")
  21.   sleep(1)
  22.   end
  23. end
  24.  
  25.  
  26. function wellsready(nw)
  27.   wellsPlaced = 0
  28.   while wellsPlaced ~= nw do
  29.     local event,modemside,senderchannel,replychannel,message,senderdistance = os.pullEvent("modem_message")
  30.     if (senderchannel==100) then
  31.       if (message=="ready") then
  32.         wellsPlaced = wellsPlaced+1
  33.         print("Totale wells klaar: "..wellsPlaced)
  34.       end
  35.     end
  36.   end
  37. end
  38.  
  39. for i=1,numRuns do
  40.   print("Run#: ".. i)
  41.   shell.run("send99","shell","wellPlace")
  42.   wellsready(numWells)
  43.   advsleep(20)
  44.   shell.run("send99","shell","emptyINV","down")
  45.   wellsready(numWells)
  46.   shell.run("send99","shell","wellGet","down")
  47.   wellsready(numWells)
  48.   shell.run("moveFrame","forward")
  49. end
  50. shell.run("moveFrame","left")
  51. sleep(1)
  52. shell.run("moveFarm","back")
  53. for i=1,numRuns do
  54.   print("Run#: ".. i)
  55.   shell.run("send99","shell","wellPlace")
  56.   wellsready(numWells)
  57.   advsleep(20)
  58.   shell.run("send99","shell","emptyINV","down")
  59.   wellsready(numWells)
  60.   shell.run("send99","shell","wellGet","down")
  61.   wellsready(numWells)
  62.   shell.run("moveFrame","back")
  63. end
  64. shell.run("moveFrame","left")
Advertisement
Add Comment
Please, Sign In to add comment