Advertisement
downwind

gohome.lua file for turtle movement in ComputerCraft

Oct 12th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. -- Modified Direwolf20's refueling and going home code to turn the turtle
  2. -- Modified by Richard Reigens 10/12/2013
  3.  
  4. local fuel, slot
  5. slot = 1
  6.  
  7. shell.run("goto.lua", "381", "62", "564") -- Sends turtle to its home position to refuel
  8. -- goto.lua is goto code from  PhyscoKillerMonkey post at http://www.computercraft.info/forums2/index.php?/topic/5665-wireless-goto-program-for-gps-turtles/page__fromsearch__1
  9. -- coordinates can be changed to anything
  10.  
  11. print("I am Home")
  12.  
  13. for i = 1, 4 do --[modified] Turns turtle to face the chest "or what ever item is in front of home position"
  14. if turtle.detect() == false then
  15.     turtle.turnRight()
  16.     else
  17.     break
  18.     end
  19. end
  20.  
  21.  
  22. fuel = turtle.getFuelLevel() -- Checks Fuel
  23. print("Fuel Level: "..fuel)
  24. if (fuel < 100) then -- If Fuel is low "less then 100" then it grabs fuel from chest and refuels
  25.     print("Refueling...")
  26.     for i = 1, 16 do
  27.     if turtle.getItemCount(i) == 0 then
  28.     turtle.select(i)
  29.     slot = i
  30.     break
  31.   end
  32. end
  33. turtle.suck()
  34. turtle.drop(turtle.getItemCount(slot) - 32) -- only grabs 32 fuel
  35. if turtle.refuel() then
  36.   print("Fueled up Successfully")
  37.   print("Fuel Level is now "..turtle.getFuelLevel())
  38. end  
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement