Posted 23 February 2013 - 10:48 PM
Title: Problem with Mining Problem.
Hello, I'm working on a Wireless/Direct Turtle Control, it contains a mining program, which is failing a little bit.
That's the Program:
LaengeO = 0
Laenge = 1
BreiteO = 0
BreiteZ = 1
LaengeZ = 1
TiefeO = 0
Tiefe = 2
TiefeZ = 2
Start = 1
Inventar = 0
Zaehlung = 1
Richtung = "left"
UpDown = 0
write("Lengt: ")
sleep(d)
repeat
l = io.read()
if l == "" then
Mine = 0
LaengeO = 1
else
LaengeO = tonumber(l)
end
until LaengeO > 0
write("Width: ")
sleep(d)
repeat
b = io.read()
if b == "" then
BreiteO = 1
else
BreiteO = tonumber(B)/>/>/>/>
end
until BreiteO > 0
write("Depth: ")
sleep(d)
repeat
t = io.read()
if t == "" then
TiefeO = 1
else
TiefeO = tonumber(t)
if TiefeZ > TiefeO then
TiefeZ = TiefeO-1
end
end
until TiefeO > 0
print("Minedirection? [Up/Down]")
sleep(d)
repeat
event, key = os.pullEvent()
if key == 200 then
print("Turtle digs up.")
UpDown = "up"
elseif key == 208 then
print("Turtle digs down.")
UpDown = "down"
else
print("False Key, press up or down.")
end
until UpDown == "up" or UpDown == "down"
local function Tanken()
turtle.select(1)
if turtle.getFuelLevel() < 10 then
Treibstoff = 0
print("Need power, start refueling…")
if turtle.getItemCount(1) < 1 then
print("No fuelitems in slot 1.")
repeat
if turtle.refuel(1) then
print("Refueling complete.")
Treibstoff = 1
else
sleep(1)
end
until Treibstoff == 1
elseif turtle.getItemCount(1) > 0 then
repeat
if turtle.refuel(1) then
print("Refueling complete.")
Treibstoff = 1
else
sleep(1)
end
until Treibstoff == 1
end
print("Refueling complete.")
end
end
local function Grabe()
while turtle.detect() do
if turtle.dig() then
else
sleep(0.25)
end
end
return true
end
local function GrabeOben()
if TiefeO >= 2 and Tiefe < TiefeO then
while turtle.detectUp() do
if turtle.digUp() then
return
else
sleep(0.25)
end
end
elseif TiefeO >= 3 and UpDown == "down" then
while turtle.detectUp() do
if turtle.digUp() then
return
else
sleep(0.25)
end
end
end
end
local function GrabeUnten()
if TiefeO >= 3 and Tiefe < TiefeO then
while turtle.detectDown() do
if turtle.digDown() then
return
else
sleep(0.25)
end
end
elseif TiefeO >= 3 and UpDown == "up" then
while turtle.detectDown() do
if turtle.digDown() then
return
else
sleep(0.25)
end
end
end
end
local function Runter()
if Tiefe < TiefeO and TiefeO > 3 then
repeat
if UpDown == "down" then
if turtle.down() then
Tiefe = Tiefe+1
Tanken()
else turtle.down()
GrabeUnten()
end
elseif UpDown == "up" then
if turtle.up() then
Tiefe = Tiefe+1
Tanken()
else
GrabeOben()
end
end
until Tiefe == TiefeO or math.fmod(Tiefe, 3) == 0
end
end
local function Hoch()
if Tiefe == TiefeO and TiefeO > 3 then
repeat
if UpDown == "down" then
if turtle.up() then
TiefeZ = TiefeZ+1
Tanken()
elseif not turtle.up() then
GrabeOben()
end
elseif UpDown == "up" then
if turtle.down() then
TiefeZ = TiefeZ+1
Tanken()
elseif not turtle.down() then
GrabeUnten()
end
end
until TiefeZ == TiefeO
Mine = 0
elseif TiefeO <= 3 then
TiefeZ = TiefeO
Mine = 0
end
end
local function Zurueck()
if Tiefe == 0 then
print("Return to start.")
end
if Richtung == "left" then
turtle.turnLeft()
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.back()
elseif Richtung == "right" then
turtle.turnRight()
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.turnRight()
while BreiteZ < BreiteO do
if turtle.back() then
Tanken()
BreiteZ = BreiteZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.turnLeft()
turtle.back()
elseif Richtung == "inaktiv" then
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.back()
end
if BreiteO > 1 then
Richtung = "left"
end
Start = 1
Laenge = 1
LaengeZ = 1
l = 1
BreiteZ = 1
end
local function Entleeren()
turtle.turnLeft()
turtle.turnLeft()
if turtle.getItemCount(15) > 0 and turtle.getItemCount(16) > 0 then
print("Unload items into chest.")
if turtle.detect() then
if not turtle.dig() then
repeat
turtle.attack()
until not turtle.detect()
end
end
turtle.select(16)
turtle.place()
turtle.select(2)
for n=2,15 do
Inventar = Inventar + turtle.getItemCount(n)
turtle.select(n)
turtle.drop()
end
elseif turtle.getItemCount(16) < 1 then
print("No chest in slot 16…\nKeep items in inventory.")
end
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
end
local function Invtest()
repeat
if turtle.getItemCount(15) > 0 then
print("Noe empty slots left.\nStart unloading into chest.")
count = "full"
if turtle.getItemCount(16) < 1 then
print("Put chests into slot 16, please.")
Slot = 0
if Slot == 0 then
repeat
if turtle.getItemCount(16) > 0 then
Slot = 1
end
sleep(5)
until Slot == 1
end
end
turtle.select(16)
if UpDown == "up" then
turtle.placeDown()
elseif UpDown == "down" then
turtle.placeUp()
end
turtle.select(2)
for n=2,15 do
Inventar = Inventar + turtle.getItemCount(n)
turtle.select(n)
if UpDown == "up" then
turtle.dropDown()
elseif UpDown == "down" then
turtle.dropUp()
end
end
turtle.select(1)
elseif not turtle.getItemCount(15) ~= 0 then
count = "empty"
end
until count == "empty"
end
local function Vor()
Tanken()
while not turtle.forward() do
if turtle.detect() then
Grabe()
elseif not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
else
sleep(0.1)
end
end
end
local function Drehen()
if BreiteO > 1 then
if Richtung == "left" then
turtle.turnLeft()
elseif Richtung == "right" then
turtle.turnRight()
end
if Laenge < LaengeO then
Grabe()
Vor()
Laenge = Laenge+1
GrabeOben()
GrabeUnten()
Invtest()
end
if Richtung == "left" then
turtle.turnLeft()
Richtung = "right"
elseif Richtung == "right" then
turtle.turnRight()
Richtung = "left"
end
end
end
local function Graben()
for b = 2, BreiteO do
Grabe()
Vor()
GrabeOben()
GrabeUnten()
if Zaehlung == 3 then
Invtest()
Zaehlung = 1
else
Zaehlung = Zaehlung+1
end
end
end
print("Start mining.")
Tanken()
while Mine == 1 do
while TiefeZ < TiefeO do
for l = 1, LaengeO do
if Start == 1 then
Grabe()
Vor()
GrabeOben()
GrabeUnten()
if BreiteO > 1 then
turtle.turnRight()
Start = 0
elseif BreiteO == 1 then
Richtung = "inaktiv"
end
end
Graben()
Drehen()
end
Zurueck()
Hoch()
if Mine == 1 then
Runter()
end
end
end
Entleeren()
print("Mining finished.\n"..Inventar.." items mined.")
When it gets a number bigger then 10, it starts mining each level twice after the 10th. I do not really understand why this is happening and I'm not so well in progamming, my knowlegde about tables is zero, for example. -.-
So when someone can help me, that would be nice. ^^
Greetings,
Nid01
Hello, I'm working on a Wireless/Direct Turtle Control, it contains a mining program, which is failing a little bit.
That's the Program:
Spoiler
Mine = 1LaengeO = 0
Laenge = 1
BreiteO = 0
BreiteZ = 1
LaengeZ = 1
TiefeO = 0
Tiefe = 2
TiefeZ = 2
Start = 1
Inventar = 0
Zaehlung = 1
Richtung = "left"
UpDown = 0
write("Lengt: ")
sleep(d)
repeat
l = io.read()
if l == "" then
Mine = 0
LaengeO = 1
else
LaengeO = tonumber(l)
end
until LaengeO > 0
write("Width: ")
sleep(d)
repeat
b = io.read()
if b == "" then
BreiteO = 1
else
BreiteO = tonumber(B)/>/>/>/>
end
until BreiteO > 0
write("Depth: ")
sleep(d)
repeat
t = io.read()
if t == "" then
TiefeO = 1
else
TiefeO = tonumber(t)
if TiefeZ > TiefeO then
TiefeZ = TiefeO-1
end
end
until TiefeO > 0
print("Minedirection? [Up/Down]")
sleep(d)
repeat
event, key = os.pullEvent()
if key == 200 then
print("Turtle digs up.")
UpDown = "up"
elseif key == 208 then
print("Turtle digs down.")
UpDown = "down"
else
print("False Key, press up or down.")
end
until UpDown == "up" or UpDown == "down"
local function Tanken()
turtle.select(1)
if turtle.getFuelLevel() < 10 then
Treibstoff = 0
print("Need power, start refueling…")
if turtle.getItemCount(1) < 1 then
print("No fuelitems in slot 1.")
repeat
if turtle.refuel(1) then
print("Refueling complete.")
Treibstoff = 1
else
sleep(1)
end
until Treibstoff == 1
elseif turtle.getItemCount(1) > 0 then
repeat
if turtle.refuel(1) then
print("Refueling complete.")
Treibstoff = 1
else
sleep(1)
end
until Treibstoff == 1
end
print("Refueling complete.")
end
end
local function Grabe()
while turtle.detect() do
if turtle.dig() then
else
sleep(0.25)
end
end
return true
end
local function GrabeOben()
if TiefeO >= 2 and Tiefe < TiefeO then
while turtle.detectUp() do
if turtle.digUp() then
return
else
sleep(0.25)
end
end
elseif TiefeO >= 3 and UpDown == "down" then
while turtle.detectUp() do
if turtle.digUp() then
return
else
sleep(0.25)
end
end
end
end
local function GrabeUnten()
if TiefeO >= 3 and Tiefe < TiefeO then
while turtle.detectDown() do
if turtle.digDown() then
return
else
sleep(0.25)
end
end
elseif TiefeO >= 3 and UpDown == "up" then
while turtle.detectDown() do
if turtle.digDown() then
return
else
sleep(0.25)
end
end
end
end
local function Runter()
if Tiefe < TiefeO and TiefeO > 3 then
repeat
if UpDown == "down" then
if turtle.down() then
Tiefe = Tiefe+1
Tanken()
else turtle.down()
GrabeUnten()
end
elseif UpDown == "up" then
if turtle.up() then
Tiefe = Tiefe+1
Tanken()
else
GrabeOben()
end
end
until Tiefe == TiefeO or math.fmod(Tiefe, 3) == 0
end
end
local function Hoch()
if Tiefe == TiefeO and TiefeO > 3 then
repeat
if UpDown == "down" then
if turtle.up() then
TiefeZ = TiefeZ+1
Tanken()
elseif not turtle.up() then
GrabeOben()
end
elseif UpDown == "up" then
if turtle.down() then
TiefeZ = TiefeZ+1
Tanken()
elseif not turtle.down() then
GrabeUnten()
end
end
until TiefeZ == TiefeO
Mine = 0
elseif TiefeO <= 3 then
TiefeZ = TiefeO
Mine = 0
end
end
local function Zurueck()
if Tiefe == 0 then
print("Return to start.")
end
if Richtung == "left" then
turtle.turnLeft()
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.back()
elseif Richtung == "right" then
turtle.turnRight()
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.turnRight()
while BreiteZ < BreiteO do
if turtle.back() then
Tanken()
BreiteZ = BreiteZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.turnLeft()
turtle.back()
elseif Richtung == "inaktiv" then
while LaengeZ < LaengeO do
if turtle.back() then
Tanken()
LaengeZ = LaengeZ+1
else
sleep(0.25)
turtle.turnRight()
turtle.turnRight()
if not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
elseif turtle.detect() then
turtle.dig()
end
turtle.turnLeft()
turtle.turnLeft()
end
end
turtle.back()
end
if BreiteO > 1 then
Richtung = "left"
end
Start = 1
Laenge = 1
LaengeZ = 1
l = 1
BreiteZ = 1
end
local function Entleeren()
turtle.turnLeft()
turtle.turnLeft()
if turtle.getItemCount(15) > 0 and turtle.getItemCount(16) > 0 then
print("Unload items into chest.")
if turtle.detect() then
if not turtle.dig() then
repeat
turtle.attack()
until not turtle.detect()
end
end
turtle.select(16)
turtle.place()
turtle.select(2)
for n=2,15 do
Inventar = Inventar + turtle.getItemCount(n)
turtle.select(n)
turtle.drop()
end
elseif turtle.getItemCount(16) < 1 then
print("No chest in slot 16…\nKeep items in inventory.")
end
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
end
local function Invtest()
repeat
if turtle.getItemCount(15) > 0 then
print("Noe empty slots left.\nStart unloading into chest.")
count = "full"
if turtle.getItemCount(16) < 1 then
print("Put chests into slot 16, please.")
Slot = 0
if Slot == 0 then
repeat
if turtle.getItemCount(16) > 0 then
Slot = 1
end
sleep(5)
until Slot == 1
end
end
turtle.select(16)
if UpDown == "up" then
turtle.placeDown()
elseif UpDown == "down" then
turtle.placeUp()
end
turtle.select(2)
for n=2,15 do
Inventar = Inventar + turtle.getItemCount(n)
turtle.select(n)
if UpDown == "up" then
turtle.dropDown()
elseif UpDown == "down" then
turtle.dropUp()
end
end
turtle.select(1)
elseif not turtle.getItemCount(15) ~= 0 then
count = "empty"
end
until count == "empty"
end
local function Vor()
Tanken()
while not turtle.forward() do
if turtle.detect() then
Grabe()
elseif not turtle.detect() then
repeat
turtle.attack()
until turtle.attack() == false
else
sleep(0.1)
end
end
end
local function Drehen()
if BreiteO > 1 then
if Richtung == "left" then
turtle.turnLeft()
elseif Richtung == "right" then
turtle.turnRight()
end
if Laenge < LaengeO then
Grabe()
Vor()
Laenge = Laenge+1
GrabeOben()
GrabeUnten()
Invtest()
end
if Richtung == "left" then
turtle.turnLeft()
Richtung = "right"
elseif Richtung == "right" then
turtle.turnRight()
Richtung = "left"
end
end
end
local function Graben()
for b = 2, BreiteO do
Grabe()
Vor()
GrabeOben()
GrabeUnten()
if Zaehlung == 3 then
Invtest()
Zaehlung = 1
else
Zaehlung = Zaehlung+1
end
end
end
print("Start mining.")
Tanken()
while Mine == 1 do
while TiefeZ < TiefeO do
for l = 1, LaengeO do
if Start == 1 then
Grabe()
Vor()
GrabeOben()
GrabeUnten()
if BreiteO > 1 then
turtle.turnRight()
Start = 0
elseif BreiteO == 1 then
Richtung = "inaktiv"
end
end
Graben()
Drehen()
end
Zurueck()
Hoch()
if Mine == 1 then
Runter()
end
end
end
Entleeren()
print("Mining finished.\n"..Inventar.." items mined.")
When it gets a number bigger then 10, it starts mining each level twice after the 10th. I do not really understand why this is happening and I'm not so well in progamming, my knowlegde about tables is zero, for example. -.-
So when someone can help me, that would be nice. ^^
Greetings,
Nid01