This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
eleectricman226's profile picture

Mining Turtle Program Help

Started by eleectricman226, 18 January 2014 - 11:15 PM
eleectricman226 #1
Posted 19 January 2014 - 12:15 AM
Ok, I am having trouble with a mining turtle program I wrote. Code:
rednet.open("right")
redet.broadcast("Turtle  Mine Program Started!")
local mine=true
print("How Long Will This Mine Be?")
length=read()
blockDis=0
blocksMined=0
estBlocks=6*length
print("Estimated Blocks Will Be Mined: "..estBlocks.."Blocks.")
print("Mining...")
while mine==true do
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
blocksMined=blocksMined+6
rednet.broadcast("Turtle Mined "..blocksMined.." Blocks.")
rednet.broadcast("Turtle Has Gone "..blockDis.." Block Out Of "..length.."  Blocks")
if blockDis==length then
mine=false
rednet.broadcast("Mining Complete!")
rednet.broadcast("Mined "..blocksMined.." Blocks Total!")
rednet.broadcast("Went "..blockDis.." "Blocks!")
end
end
My issue is that when it goes through the if statement "if blockDis==length then", it won't trigger when that should be true. I Don't Know Why It Isn't Triggering. Also, here is the code for the computer that gets the data of the broadcasting:
rednet.open("top")
print("Waiting  For Turtle Data...")
while true do
id, message = rednet.receive()
if id==7 then
print(message)
end
end
OReezy #2
Posted 19 January 2014 - 02:24 AM
You don't increment blockDis anywhere so it will always be 0. Also, what you are trying to achieve may be easier with a for loop
for i=1,length do
  --do stuff
end
eleectricman226 #3
Posted 19 January 2014 - 08:02 AM
Ah, I didn't actually see that. Thanks for the help :D/>/>

Ok, I updated that part of the code, putting
rednet.broadcast("Turtle Mined "..blocksMined.." Blocks")blockDis=blockDis+1
rednet.broadcast("Turtle Has Gone "..blockDis.." Blocks Out  Of "..length.." Blocks")
And is still goes over the length. Any Idea?
CometWolf #4
Posted 19 January 2014 - 02:17 PM
because blockDis is a number and length is a string, and they will thus never be the same.

length = tonumber(read()) -- converts from string to number