Advertisement
Guest User

motion

a guest
May 22nd, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. x,y,z,dir=0,0,0,0
  2. fuelSlot=1
  3. function refuel()
  4.   turtle.select(fuelSlot)
  5.   turtle.refuel(1)
  6. end
  7. function forward()
  8.   reussit=turtle.forward()
  9.   if not reussit then
  10.     if turtle.getFuelLevel()==0 then
  11.       refuel()
  12.     else
  13.       turtle.dig()
  14.     end
  15.     reussit=turtle.forward()
  16.   end
  17.   if reussit then
  18.     if dir==0 then
  19.       x=x+1
  20.     elseif dir==1 then
  21.       y=y+1
  22.     elseif dir==2 then
  23.       x=x-1
  24.     elseif dir==3 then
  25.       y=y-1
  26.     end
  27.   end
  28.   return reussit
  29. end
  30. function back()
  31.   reussit=turtle.back()
  32.   if not reussit then
  33.     if turtle.getFuelLevel()==0 then
  34.       refuel()
  35.     end
  36.     reussit=turtle.back()
  37.   end
  38.   if reussit then
  39.     if dir==0 then
  40.       x=x-1
  41.     elseif dir==1 then
  42.       y=y-1
  43.     elseif dir==2 then
  44.       x=x+1
  45.     elseif dir==3 then
  46.       y=y+1
  47.     end
  48.   end
  49.   return reussit
  50. end
  51. function up()
  52.   reussit=turtle.up()
  53.   if not reussit then
  54.     if turtle.getFuelLevel()==0 then
  55.       refuel()
  56.     else
  57.       turtle.digUp()
  58.     end
  59.     reussit=turtle.up()
  60.   end
  61.   if reussit then
  62.     z=z+1
  63.   end
  64.   return reussit
  65. end
  66. function down()
  67.   reussit=turtle.down()
  68.   if not reussit then
  69.     if turtle.getFuelLevel()==0 then
  70.       refuel()
  71.     else
  72.       turtle.digDown()
  73.     end
  74.     reussit=turtle.down()
  75.   end
  76.   if reussit then
  77.     z=z-1
  78.   end
  79.   return reussit
  80. end
  81. function turnRight()
  82.   turtle.turnRight()
  83.   dir=(dir+1)%4
  84. end
  85. function turnLeft()
  86.   turtle.turnLeft()
  87.   dir=dir-1
  88.   if dir==-1 then
  89.     dir=0
  90.   end
  91. end
  92. function setDir(d)
  93.   dif=dir-d
  94.   if math.abs(dif)>2 then
  95.     if dif>0 then
  96.       dif=4+dif
  97.     else
  98.       dif=dif-4
  99.     end
  100.   end
  101.   while dir~=d do
  102.     if dif>0 then
  103.       turnLeft()
  104.     else
  105.       turnRight()
  106.     end
  107.   end
  108. end
  109. function reset()
  110.   x,y,z,dir=0,0,0,0
  111. end
  112. function setFuelSlot(s)
  113.   fuelSlot=s
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement