Posted 29 March 2013 - 09:21 AM
Hi guys i wrote a mining programm and there is sometimes, when it goes on a new y layer this error message:
automine:237: attempt to call number
Its very annoying because i don't know my fault and can't find it out.
here is the mining programm itself (http://pastebin.com/ld0rbwi0):
And here is my goto programm which i'm using in the mining programm (http://pastebin.com/kx0ygmdg):
I'm able to request the correct position (gps locate) with the turtle, on exact the same place where it stopps.
Sorry for bad english ;)/>
Thank you for reading and may helping :)/>
automine:237: attempt to call number
Its very annoying because i don't know my fault and can't find it out.
here is the mining programm itself (http://pastebin.com/ld0rbwi0):
Spoiler
--[[Thank you for downloading my
programm, i hope you have
some fun with it :)/>
Write for the doreset a 1, every
time you set the turtle up and run
the program. After you turn it back
to 0 and the turtle will start mining.]]--
local doreset = 0
--[[Here you have to set type in the
coordinates, where the turtle should
mine. But be careful, the variables
which got a max in it must be greater
the the ones with a min in the name!
Otherwise the turtle mines endless
and in the false place.]]--
maxx = -209
minx = -215
maxy = 75
miny = 50
maxz = 290
minz = 283
function reset()
if turtle.getItemCount(16) > 0 then
turtle.select(14)
turtle.drop()
end
file = fs.open("end", "w")
file.writeLine(0)
file.close()
file = fs.open("y", "w")
file.writeLine(mgoy)
file.close()
file = fs.open("gonewy", "w")
file.writeLine(0)
file.close()
turtle.select(16)
turtle.transferTo(14,1)
end
function invClear(a)
if turtle.getItemCount(12) > 0 and a == 0 then
turtle.select(16)
while not turtle.placeUp() do
turtle.digUp()
end
for i = 1, 14 do
turtle.select(i)
turtle.dropUp()
end
turtle.select(16)
turtle.digUp()
end
end
function refuel(x, y)
if y then
invClear(1)
else
invClear(0)
end
if x > turtle.getFuelLevel() then
turtle.select(15)
while not turtle.placeUp() do
turtle.digUp()
end
end
while x > turtle.getFuelLevel() do
turtle.suckUp()
turtle.refuel()
end
turtle.select(15)
turtle.digUp()
end
function mine(x)
refuel(x + 10)
for i = 1, x do
if turtle.getItemCount(12) > 0 then
invClear(0)
end
while not turtle.forward() do
turtle.dig()
end
while turtle.detectUp() do
turtle.digUp()
end
turtle.digDown()
end
end
function turning()
if richtung == 0 then
turtle.turnRight()
mine(1)
turtle.turnRight()
richtung = 1
else
turtle.turnLeft()
mine(1)
turtle.turnLeft()
richtung = 0
print(richtung)
end
end
function calcx()
if (mgox - mendx) >= 0 then
return mgox - mendx
else
return mendx - mgox
end
end
function calcy()
if (mgoy - mendy) >= 0 then
return mgoy - mendy
else
return mendy - mgoy
end
end
function calcz()
if (mgoz - mendz) >= 0 then
return mgoz - mendz
else
return mendz - mgoz
end
end
function calcstart()
rednet.open("right")
cx, cy, cz = gps.locate(3)
if (mgox - cx) >= 0 then
x = mgox - cx
else
x = cx - mgox
end
if (mgoy - cy) >= 0 then
y = mgoy - cy
else
y = cy - mgoy
end
if (mgoz - cz) >= 0 then
z = mgoz - cz
else
z = cz - mgoz
end
return x + y + z + 200
end
function getvariables()
cx, cy, cz = gps.locate(3)
mnx = mgox
if cz == mendz then
mnz = mgoz
else
mnz = cz
end
file = fs.open("y", "r")
mny = file.readLine()
file.close()
mny = tonumber(mny)
file = fs.open("end", "r")
ended = file.readLine()
file.close()
ended = tonumber(ended)
file = fs.open("gonewy", "r")
gonewy = file.readLine()
file.close()
gonewy = tonumber(gonewy)
end
function start()
if turtle.getItemCount(16) == 0 then
while cx ~= mgox or cy ~= mgoy + 2 or cz ~= mgoz do
refuel(calcstart(1))
shell.run("goto", mgox, mgoy + 2, mgoz, "1")
cx, cy, cz = gps.locate(3)
end
turtle.select(14)
turtle.transferTo(16, 1)
turtle.select(1)
elseif gonewy ~= 1 then
while cx ~= mnx or cy ~= mny + 2 or cz ~= mnz do
refuel(calcx() + calcz() + 50)
shell.run("goto", mnx, mny + 2, mnz, "1")
cx, cy, cz = gps.locate(3)
end
else
while cx ~= mgox or cy ~= mny + 2 or cz ~= mgoz do
refuel(calcx() + calcz() + 50)
shell.run("goto", mgox, mny + 2, mgoz, "1")
cx, cy, cz = gps.locate(3)
end
file = fs.open("gonewy","w")
file.writeLine(0)
file.close()
end
for i = 1, 2 do
while not turtle.down() do
turtle.digDown()
end
end
turtle.digDown()
end
function debug()
if turtle.getItemCount(16) > 0 then
turtle.select(15)
turtle.digUp()
elseif turtle.getItemCount(13) > 0 then
else
turtle.select(16)
turtle.digUp()
end
end
function newy()
if mny - 3 >= mendy then
nexty(3)
elseif mny - 2 == mendy then
nexty(2)
elseif mny - 1 == mendy then
nexty(1)
elseif mny == mendy then
file = fs.open("end", "w")
file.writeLine(1)
file.close()
ended = 1
else
print("epic fail")
end
if ended == 0 then
file = fs.open("gonewy", "w")
file.writeLine(1)
file.close()
end
end
function nexty(x)
nexty = mny - x
file = fs.open("y", "w")
file.writeLine(nexty)
file.close()
end
function back()
invClear()
mnx = mgox
mny = mgoy
mnz = mgoz
start()
turtle.up()
turtle.up()
end
function chegz()
cx, cy, cz = gps.locate(3)
if mendz == cz then
tf = 1
elseif cz < mendz then
tf = 1
else
tf = 0
end
end
mgox = maxx
mendx = minx
mgoy = maxy - 1
mendy = miny + 1
mgoz = maxz
mendz = minz + 1
richtung = 0
tf = 0
debug()
if doreset == 0 then
print("I'm mining because you are to lazy :P/>")
getvariables()
while ended == 0 do
getvariables()
start()
richtung = 0
chegz()
while tf == 0 do
mine(calcx())
chegz()
turning()
end
mine(calcx())
getvariables()
newy()
if ended == 1 then
print("I'm done!")
end
end
back()
else
reset()
print("reset")
end
And here is my goto programm which i'm using in the mining programm (http://pastebin.com/kx0ygmdg):
Spoiler
local ziel = {...}
local zx = ziel[1]
local zy = ziel[2]
local zz = ziel[3]
local zdirect = ziel[4]
zx = zx +0
zy = zy +0
zz = zz +0
zdirect = zdirect +0
--shell.run("clear")
--[[function turn(ndirect)
while ndirect ~= direct do
turtle.turnRight()
if direct ~= 3 then
direct = direct + 1
else
direct = 0
end
end
end]]--
rednet.open("right")
local fx, fy, fz = gps.locate(3)
for i = 1, 4 do
if turtle.forward() then
sx, sy, sz = gps.locate(3)
direct = nil
if fz < sz then
direct = 0
elseif fz > sz then
direct = 2
elseif fx > sx then
direct = 1
elseif fx < sx then
direct = 3
end
break
else
turtle.turnRight()
end
end
function turn(ndirect)
while ndirect ~= direct do
turtle.turnRight()
if direct ~= 3 then
direct = direct + 1
else
direct = 0
end
end
end
if direct ~= nil then
local fail = 0
function z0()
if zz > sz then
turn(0)
if turtle.forward() then
sz = sz + 1
fail = 0
z0()
else
x1()
end
else
x1()
end
end
function x1()
if zx < sx then
turn(1)
if turtle.forward() then
sx = sx - 1
fail = 0
x1()
else
z2()
end
else
z2()
end
end
function z2()
if zz < sz then
turn(2)
if turtle.forward() then
sz = sz - 1
fail = 0
z2()
else
x3()
end
else
x3()
end
end
function x3()
if zx > sx then
turn(3)
if turtle.forward() then
sx = sx + 1
fail = 0
x3()
else
yu()
end
else
yu()
end
end
function yu()
if fail ~= 1 then
if zy > sy then
if turtle.up() then
sy = sy + 1
fail = 0
yu()
else
yd()
end
else
yd()
end
elseif zy ~= sy then
else
turtle.up()
sy = sy + 1
z0()
end
end
function yd()
if zy < sy then
if turtle.down() then
sy = sy - 1
fail = 0
yd()
else
-- z0()
cheg()
end
else
-- z0()
cheg()
end
end
function cheg()
if fail == 1 then
if zx == sx then
if zy == sy then
if zz == sz then
-- print("Ich bin angekommen und schalte ab!")
else
print("fail")
end
else
print("fail")
end
else
print("fail")
end
else
if fail == 0 then
if zx == sx then
if zy == sy then
if zz == sz then
-- print("Ich bin angekommen und schalte ab!")
else
fail = 1
z0()
end
else
fail = 1
z0()
end
else
fail = 1
z0()
end
end
end
end
z0()
turn(zdirect)
else
print("I need space arround me!")
end
I'm able to request the correct position (gps locate) with the turtle, on exact the same place where it stopps.
Sorry for bad english ;)/>
Thank you for reading and may helping :)/>