Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x,y,z,dir=0,0,0,0
- fuelSlot=1
- function refuel()
- turtle.select(fuelSlot)
- turtle.refuel(1)
- end
- function forward()
- reussit=turtle.forward()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.dig()
- end
- reussit=turtle.forward()
- end
- if reussit then
- if dir==0 then
- x=x+1
- elseif dir==1 then
- y=y+1
- elseif dir==2 then
- x=x-1
- elseif dir==3 then
- y=y-1
- end
- end
- return reussit
- end
- function back()
- reussit=turtle.back()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- end
- reussit=turtle.back()
- end
- if reussit then
- if dir==0 then
- x=x-1
- elseif dir==1 then
- y=y-1
- elseif dir==2 then
- x=x+1
- elseif dir==3 then
- y=y+1
- end
- end
- return reussit
- end
- function up()
- reussit=turtle.up()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.digUp()
- end
- reussit=turtle.up()
- end
- if reussit then
- z=z+1
- end
- return reussit
- end
- function down()
- reussit=turtle.down()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.digDown()
- end
- reussit=turtle.down()
- end
- if reussit then
- z=z-1
- end
- return reussit
- end
- function turnRight()
- turtle.turnRight()
- dir=(dir+1)%4
- end
- function turnLeft()
- turtle.turnLeft()
- dir=dir-1
- if dir==-1 then
- dir=0
- end
- end
- function setDir(d)
- dif=dir-d
- if math.abs(dif)>2 then
- if dif>0 then
- dif=4+dif
- else
- dif=dif-4
- end
- end
- while dir~=d do
- if dif>0 then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- function reset()
- x,y,z,dir=0,0,0,0
- end
- function setFuelSlot(s)
- fuelSlot=s
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement