Posted 20 January 2014 - 10:01 AM
Hello this is my first post on this site, i worked on this program for a good 30-60 minutes and couldn't get it working.
What i am trying to do is get it to mine however many blocks the user wants, then ask him how many different tunnels to make.
The problem i have is that i cant get it to switch which way it needs to turn, it needs to mine straight then go right, then mine straight then go left. The way I tried to make this is with the increment operation and to decide if the number is positive then to turn right, and if its not turn left.
Any other ideas for how i could do this?
Code:
What i am trying to do is get it to mine however many blocks the user wants, then ask him how many different tunnels to make.
The problem i have is that i cant get it to switch which way it needs to turn, it needs to mine straight then go right, then mine straight then go left. The way I tried to make this is with the increment operation and to decide if the number is positive then to turn right, and if its not turn left.
Any other ideas for how i could do this?
Code:
print("How long do you want to tunnel?")
local length = read()
print("Okay and how many tunnels?")
local n = read()
print("Going: ", length, " long with ", n, " different tunnels")
x = length
c=0
local function tryRefuel()
for i = 1,16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
if turtle.refuel(1) then
return true
end
end
end
turtle.select(1)
return false
end
local function refuel()
curFuel = turtle.getFuelLevel()
if curFuel == "unlimited" or curFuel >= 10 then
return
else
if not tryRefuel() then
print("Please supply more fuel to coninue...")
while not tryRefuel() do
sleep(1)
end
end
end
end
function mod(a, B)/>
return a - (math.floor(a/B)/>)
end
function tunnel()
for i=0,x do
refuel()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
end
end
function loop()
local c = 0
for a=0,n do
tunnel()
if(mod(c,2) == 0) then
turtle.turnRight()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.turnRight()
end
if(mod(c,2) == 1) then
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
turtle.forward()
turtle.turnLeft()
end
c = c + 1
end
end
loop()