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

Mining Program Help

Started by Raron70, 21 December 2012 - 08:26 PM
Raron70 #1
Posted 21 December 2012 - 09:26 PM
Hello I made a turtle mining program but the turtle wont go up to the surface is done mining

here the script:



fuel = turtle.getFuelLevel()
if fuel == 0 then
turtle.select(14)
turtle.refuel(1)
turtle.select(1)

end

check = turtle.getItemCount(13)
if check <= 1 then
print("Put Torches In Slot 13 !")
sleep(1)
os.shutdown()
end

for i = 1,56 do
turtle.digDown()
turtle.down()
if i == 56 then
while true do
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.select(13)
turtle.place()
turtle.select(1)
turtle.turnRight()
turtle.down()

invfull = turtle.getItemCount(16)
if invfull == 64 then
turtle.up()
while true do
turtle.back()
while not turtle.back() do
for g = 1,56 do
turtle.up()
sleep(1)
os.shutdown()
end

torch = turtle.getItemCount(13)
if torch <= 1 then
os.shutdown()

fuel = turtle.getFuelLevel()
if fuel == 0 then
turtle.select(14)
turtle.refuel(1)
turtle.select(1)

end
end
end
end
end
end
end
end

please help me
remiX #2
Posted 21 December 2012 - 11:17 PM
Why are you making the turtle shutdown?
Raron70 #3
Posted 22 December 2012 - 04:10 PM
when the turtle is at the surface i want him to shutdown
Doyle3694 #4
Posted 22 December 2012 - 04:23 PM
Please, indent your code. It will be alot more eyepleasing to read that way
Raron70 #5
Posted 22 December 2012 - 04:37 PM
indent?
Zoinky #6
Posted 22 December 2012 - 04:51 PM
Please, indent your code. It will be alot more eyepleasing to read that way
indent?

fuel = turtle.getFuelLevel()
if fuel == 0 then
turtle.select(14)
turtle.refuel(1)
turtle.select(1)
end
check = turtle.getItemCount(13)
if check <= 1 then
print("Put Torches In Slot 13 !")
sleep(1)
os.shutdown()
end
for i = 1,56 do
turtle.digDown()
turtle.down()
if i == 56 then
   while true do
	 turtle.dig()
	 turtle.forward()
	 turtle.digUp()
	 turtle.dig()
	 turtle.forward()
	 turtle.digUp()
	 turtle.dig()
	 turtle.forward()
	 turtle.digUp()
	 turtle.up()
	 turtle.turnLeft()
	 turtle.dig()
	 turtle.select(13)
	 turtle.place()
	 turtle.select(1)
	 turtle.turnRight()
	 turtle.down()
	 invfull = turtle.getItemCount(16)
	 if invfull == 64 then
	   turtle.up()
	   while true do
		 turtle.back()
		 while not turtle.back() do
		   for g = 1,56 do
			turtle.up()
			sleep(1)
			os.shutdown()
		   end
			
		 torch = turtle.getItemCount(13)
		 if torch <= 1 then
		  os.shutdown()
		  fuel = turtle.getFuelLevel()
		  if fuel == 0 then
			turtle.select(14)
			turtle.refuel(1)
			turtle.select(1)
       end
      end
     end
    end
   end
  end
 end
end
I tried. Lol :S

EDIT: Edited it and made it worse. Pointless now. :S
Raron70 #7
Posted 22 December 2012 - 04:55 PM
Thanks for the indent
Luanub #8
Posted 22 December 2012 - 05:35 PM
Here is some indentation with spaces, the forums handle them better then tabs.
Spoiler

fuel = turtle.getFuelLevel()
if fuel == 0 then
  turtle.select(14)
  turtle.refuel(1)
  turtle.select(1)
end

check = turtle.getItemCount(13)
if check <= 1 then
  print("Put Torches In Slot 13 !")
  sleep(1)
  os.shutdown()
end

for i = 1,56 do
  turtle.digDown()
  turtle.down()
  if i == 56 then
	while true do
	  turtle.dig()
	  turtle.forward()
	  turtle.digUp()
	  turtle.dig()
	  turtle.forward()
	  turtle.digUp()
	  turtle.dig()
	  turtle.forward()
	  turtle.digUp()
	  turtle.up()
	  turtle.turnLeft()
	  turtle.dig()
	  turtle.select(13)
	  turtle.place()
	  turtle.select(1)
	  turtle.turnRight()
	  turtle.down()
	  invfull = turtle.getItemCount(16)
	  if invfull == 64 then
		turtle.up()
		while true do
		  turtle.back()
		  while not turtle.back() do
			for g = 1,56 do
			  turtle.up()  --on the first loop it goes up
			  sleep(1)  --then it sleeps
			  os.shutdown()  --then it shutsdown here, this needs to be outside the loop.
			end
			torch = turtle.getItemCount(13)
			if torch <= 1 then
			  os.shutdown()
			  fuel = turtle.getFuelLevel()
			  if fuel == 0 then
				turtle.select(14)
				turtle.refuel(1)
				turtle.select(1)
			  end
			end
		  end
		end
	  end
	end
  end
end

Without going over it to much I think that it is because you do an os.shutdown() during your for loop that is supposed to move the turtle back to the surface. So it moves 1 spot up and shuts itself off. I've put a comment next to what I think is the offending line.

EDIT: Okay it didn't really like the spaces either… I think it may be due to how much indenting is needed due to all the nesting..
Edited on 22 December 2012 - 04:37 PM
ChunLing #9
Posted 22 December 2012 - 05:55 PM
Yes, remove all the shutdown for now. All of them.
Raron70 #10
Posted 22 December 2012 - 06:38 PM
Thanks !!!
remiX #11
Posted 23 December 2012 - 12:00 AM
Thanks !!!

Is it working now?