goreae

[CC] Pet Turtle

Feb 21st, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. function forward(n)
  2.   for i=1,n do
  3.         while not turtle.detectDown() do
  4.           turtle.down()
  5.         end
  6.         if not turtle.forward() then
  7.           if not turtle.detectDown() then
  8.                 turtle.down()
  9.           end
  10.           if not turtle.up() then
  11.                 break
  12.           end
  13.           if not turtle.forward() then
  14.                 turtle.down()
  15.                 break
  16.           end
  17.         end
  18.         if not turtle.detectDown() then
  19.           turtle.down()
  20.         end
  21.   end
  22. end
  23. function right(n)
  24.   turtle.turnRight()
  25.   forward(n)
  26. end
  27. function left(n)
  28.   turtle.turnLeft()
  29.   forward(n)
  30. end
  31. function back(n)
  32.   turtle.turnRight()
  33.   turtle.turnRight()
  34.   forward(n)
  35. end
  36. while true do
  37.   dir=math.random(1,4)
  38.   n=math.random(1,4)
  39.   if dir==1 then
  40.         forward(n)
  41.   end
  42.   if dir==2 then
  43.         right(n)
  44.   end
  45.   if dir==3 then
  46.         back(n)
  47.   end
  48.   if dir==4 then
  49.         left(n)
  50.   end
  51.   if turtle.getFuelLevel()<100 then
  52.         turtle.refuel()
  53.   end
  54.   if not (math.random(1,4)==1) then
  55.         sleep(math.random(1,5))
  56.   end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment