Posted 12 December 2012 - 07:48 AM
Hello!
So yesterday and today i have tried to make a turtle dig kinda advanced(for me)v1.0 i call it anyway i have some problems
(i enter the rednet information from a manager computer i have it simply sends !dig("what the user types", "what the user types") and sends it to the turtle:)
1. For example: I input !dig(3,3) to it it goes to position and digs down 1 and goes on put stops at two and in the end it makes a hole that is 3deap 3 long and only 2 wide why?
2. It can't come up gives me this error: startup:64: Attempt To Perform Arithmetic __div on nil and number
Please help i have thought about this very long and i guess it's some easy explanation that i have missed somewhere.
Here is the code for the turtle (feel free to try and use it and figure out a solution :)/> !)
So yesterday and today i have tried to make a turtle dig kinda advanced(for me)v1.0 i call it anyway i have some problems
(i enter the rednet information from a manager computer i have it simply sends !dig("what the user types", "what the user types") and sends it to the turtle:)
1. For example: I input !dig(3,3) to it it goes to position and digs down 1 and goes on put stops at two and in the end it makes a hole that is 3deap 3 long and only 2 wide why?
2. It can't come up gives me this error: startup:64: Attempt To Perform Arithmetic __div on nil and number
Please help i have thought about this very long and i guess it's some easy explanation that i have missed somewhere.
Here is the code for the turtle (feel free to try and use it and figure out a solution :)/> !)
rednet.open("right")
local y=0
local manageServerId = 12
local errors=0
term.clear()
term.setCursorPos(1,1)
print("Mining Turtle 1.0 Initialized!")
function goUp(loopAmount)
for i=1, loopAmount do
if turtle.up() then
y=y-1
return true
else
errors=errors+1
return false
end
end
end
function forward()
if turtle.forward() then
return true
else
errors=errors+1
return false
end
end
function forwardLoop(loopAmount)
for i=1, loopAmount do
if turtle.forward() then
return true
else
errors=errors+1
return false
end
end
end
function digForward()
if turtle.dig() and turtle.forward() then
return true
else
errors=errors+1
return false
end
end
function digForwardLoop(loopAmount)
for i=1, loopAmount do
if turtle.dig() and turtle.forward() then
return true
else
errors=errors+1
return false
end
end
end
function returnToSurface()
forwardLoop(math.floor(radius/2))
turtle.turnLeft()
forward()
if math.fmod(y, 2) == 0 then
turtle.turnLeft()
turtle.turnLeft()
end
goUp(y)
print("And Were Up! \nFuel Level Is At: "..turtle.getFuelLevel())
rednet.send(managerServerId, "And Were Up! \nFuel Level Is At: "..turtle.getFuelLevel())
end
function dig(deapth, radius)
turtle.refuel(1)
rednet.send(manageServerId, "Starting To Dig!")
for i=1, math.floor(radius/2) do
if turtle.back() then
else
errors=errors+1
end
end
turtle.turnRight()
for i=1, math.floor(radius/2) do
if turtle.back() then
else
errors=errors+1
end
end
rednet.send(manageServerId, "We have moved in position!")
while errors <= 7 do
if y<=deapth then
if turtle.digDown() and turtle.down() then
y=y+1
else
errors=errors+1
end
for i=1, radius do
if i ~= radius then
if math.fmod(i, 2)==0 then
digForwardLoop(radius)
turtle.turnRight()
digForward()
turtle.turnRight()
else
digForwardLoop(radius)
turtle.turnLeft()
digForward()
turtle.turnLeft()
end
else
if math.fmod(i, 2)==0 then
digForwardLoop(radius)
turtle.turnLeft()
digForwardLoop(radius)
turtle.turnLeft()
else
digForwardLoop(radius)
turtle.turnLeft()
turtle.turnLeft()
end
end
end
elseif y > deapth then
print("Coming Up!")
rednet.send(managerServerId, "Coming Up!")
print(errors)
break
end
end
returnToSurface()
end
while true do
senderId, message, distance = rednet.receive()
local b = string.sub(string.gsub(message, "%)", ""),5)
local c = string.gsub(b, "%(", "")
local d = string.gsub(c, ",.*", "")
local r = string.gsub(b, "%(.*,", "")
print("Using Deapth: "..d.. " And Radius: "..r)
dig(tonumber(d-1), tonumber(r))
end