libraryaddict

Untitled

Apr 27th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. --Side
  2. Distance = 10
  3. function Pos()
  4.   fsp = io.open("Position", "w")
  5.   fsp:write("Position = "..[["]]..Position..[["]])
  6.   fsp:close()
  7. end
  8. rednet.open("right")
  9. if fs.exists("Position") then
  10.   dofile("Position")
  11. else
  12.   write("Am I front or back? ")
  13.   Position = read()
  14.   Pos()
  15. end
  16.  
  17. function Check()
  18.   if turtle.getItemCount(1) > turtle.getItemCount(2) then
  19.     turtle.select(1)
  20.   else
  21.     turtle.select(2)
  22.   end
  23. end
  24.  
  25. function Heave()
  26.   if Position == "front" then
  27.     turtle.placeDown()
  28.     while not turtle.forward() do
  29.     end
  30.   elseif Position == "back" then
  31.     turtle.dig()
  32.     while not turtle.forward() do
  33.     end
  34.   else
  35.     error("Its not front or back")
  36.   end
  37.   rednet.send(ID, "Ho!")
  38. end
  39.  
  40. function Changeover()
  41.   Check()
  42.   if Position == "front" then
  43.     local BMan = 0
  44.     repeat
  45.       BMan = BMan+1
  46.       while not turtle.back() do
  47.       end
  48.     until BMan == Distance
  49.     while not turtle.down() do
  50.     end
  51.     Position = "back"
  52.   elseif Position == "back" then
  53.     while not turtle.up() do
  54.     end
  55.     while not turtle.up() do
  56.     end
  57.     local BMan = 0
  58.     repeat
  59.       BMan = BMan+1
  60.       while not turtle.forward() do
  61.       end
  62.     until BMan == Distance
  63.     while not turtle.down() do
  64.     end
  65.     Position = "front"
  66.   end
  67.   Pos()
  68.   rednet.send(ID, "Changedover!")
  69. end
  70.  
  71. while true do
  72.   ID, Msg = rednet.receive()
  73.   if Position == "front" then
  74.     if Msg == "Heave!" then
  75.       Heave()
  76.     elseif Msg == "Changeover" then
  77.       Changeover()
  78.     end
  79.   elseif Position == "back" then
  80.     if Msg == "Heave!" then
  81.       Heave()
  82.     elseif Msg == "Changeover" then
  83.       Changeover()
  84.     end
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment