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

Miner turtle stuck on Slime

Started by TyCamden, 23 November 2014 - 03:46 PM
TyCamden #1
Posted 23 November 2014 - 04:46 PM
I made a vertical miner turtle program that works just like I want it to.

But the last time I ran it, it couldn't move down because of a slime directly underneath the turtle, but it thought it had. So it just spun in place forever and ever.

Perhaps I could add a section to the program to look for slimes below it and kill them, before trying to move down?

Here is the current program…


-- before running program, be sure...
--    coal is in slot 16
--    cobble in slot 15
--    put an actual chest ABOVE the turtle that will be on the mission (empty) (for the loot)
--    put an actual chest BEHIND the turtle that will be on the mission (with more coal in it)
ypos = 0 -- This tracks how far down turtle is from its starting position
facing = 0 -- This tracks direction turtle is facing 0=original-front 1=left 2=right 3=back
mission = 1 -- Current status of mission.
			   -- 0 means mission completed
			   -- 1 means operational mission, still running.
			   -- 2 means that it is time to drop off stuff then return to where u left off
			   -- 3 means that it is time to refuel
while mission ~= 0 do
	  FuelLeft = turtle.getFuelLevel() + 1
	  if FuelLeft < 65 then -- if there is less than 65 fuel in the turtle...
		 mission = 3
		 if turtle.getItemCount(16) > 0 then -- if there is at least 1 item in coal-slot 16...
		    turtle.select(16) -- choose slot 16 on turtle
		    turtle.refuel(1) -- refuel turtle with 1 item from slot 16
		    turtle.select(1) -- choose slot 1 on turtle (default?)
		    mission = 1
		 else
			 -- coal slot is empty so go back and get more fuel into slot 16
			 yrem = ypos -- remember ypos before returning for fuel
			 facrem = facing -- remember facing before returning for fuel
			 if ypos == 0 then -- you are back at start
			    -- get turtle facing the chest (backwards from original direction
			    if facing == 0 then -- facing forward
				   turtle.turnLeft() -- turn left
				   turtle.turnLeft() -- turn left
				   facing = 3
			    end
			    if facing == 1 then -- facing left
				   turtle.turnLeft() -- turn left
				   facing = 3
			    end
			    if facing == 2 then -- facing right
				   turtle.turnRight() -- turn right
				   facing = 3
			    end
			    -- see if fuel chest is empty or not and get more fuel
			    turtle.select(16) -- choose slot 16 on turtle
			    turtle.suck() -- suck fuel out of chest into slot 16 if possible
			    turtle.turnRight() -- turning turtle back towards facing the front
				   facing = 1
			    turtle.turnRight() -- finishing turning turtle to facing the front
				   facing = 0
			    turtle.refuel(1) -- refuel turtle with 1 item from slot 16
			    turtle.select(1) -- choose slot 1 on turtle (default?)
			    FuelLeft = turtle.getFuelLevel() + 1
			    if FuelLeft < 65 then -- still less than 65 fuel after refueling attempt
				   print "Not enough fuel to continue mission."
			    else
				    -- RETURN TO POSITION PRIOR TO NEEDING FUEL IF NECESSARY
				    while yrem ~= ypos do
					   turtle.down()
					   ypos = ypos - 1
				    end
				    while facrem ~= facing do
						  turtle.turnRight()
						  if facing == 0 then -- 0=original-front 1=left 2=right 3=back
							 facing = 2
						  else
							  if facing == 1 then
								 facing = 0
							  else
								  if facing == 2 then
									 facing = 3
								  else
									  -- facing = 3
									  facing = 1
								  end
							  end
						  end
				    end
				    mission = 1
			    end
			 else
				 -- move back up to start
				 while ypos<0 and ypos~=0 do
					   turtle.up()
					   ypos = ypos + 1
				 end
			 end
		 end
	  else  -- if there is NOT less than 65 fuel in the turtle...
		    if turtle.down() then -- it was able to move down
			   ypos = ypos - 1
		    else -- it cannot move down
			    -- find out what is below it and act accordingly
			    local bSuccess, tData = turtle.inspectDown()
			    if bSuccess and tData.name == "minecraft:chest" then
				   turtle.suckDown()
				   turtle.select(15)
				   turtle.placeDown()
				   turtle.select(1)
				   mission = 2 -- drop off all new stuff after grabbing a rare chest
			    else
				    if bSuccess and tData.name == "minecraft:bedrock" then -- bottom of the world
					   mission = 0
					   while ypos ~= 0 do
							 turtle.up()
							 ypos = ypos + 1
							 -- fill below turtle with cobble IF there is cobble in slot 15
							 cobcnt = turtle.getItemCount(15)
							 if cobcnt <1 then
							    for i = 1, 14 do
								    sltcnt = turtle.getItemCount(i)
								    if sltcnt > 0 then
									   wut = turtle.getItemDetail(i)
									   if wut.name == "minecraft:cobblestone" then
										  turtle.select(i)
										  turtle.transferTo(15)
										  turtle.select(1)
									   end
								    end
							    end
							 end
							 turtle.select(15)
							 turtle.placeDown()
							 turtle.select(1)
					   end
				    else
					    turtle.digDown()
					    turtle.down()
					    ypos = ypos - 1
				    end
			    end
		    end
		    if mission~=2 and mission~=0 then
			   -- seal any holes around this location (main concern: lava)
			   for i = 1, 4 do
				   if turtle.detect()=="false" then
					  -- there is a hole
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
					  turtle.turnLeft()
				   end
			   end
			   -- look around for goodies
			   flag = 0
			   for i = 1, 4 do
				   local bSuccess, tData = turtle.inspect()
				   if bSuccess and tData.name == "minecraft:stone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:cobblestone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:dirt" then
					  flag = 1
				   end
				   -- if the flag is still zero, it may be valuable
				   --  and just get rid of gravel
				   if flag == 0 then
					  turtle.dig()
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
				   end
				   turtle.turnLeft()
				   flag = 0
			   end
		    else
			    -- mission = 2 (or 0)
			    --    2 means that it is time to drop off stuff then return to where u left off
			    -- there is a chest ABOVE the turtle start position for the loot
			    yrem = ypos -- remember ypos before returning for fuel
			    while ypos ~= 0 do
					  turtle.up()
					  ypos = ypos + 1
			    end
			    -- top off slot 15 (cobble) to 64 items - if possible from goodies collected
			    cobb = turtle.getItemCount(15)
			    if cobb < 64 then
					  for i = 1, 14 do
						  ctslt = turtle.getItemCount(i)
						  if ctslt ~= 0 then
							 wut = turtle.getItemDetail(i)
							 if wut.name == "minecraft:cobblestone" then
							    turtle.select(i)
							    turtle.transferTo(15)
							    end
						  end
					  end
			    end
			    turtle.select(1)
			    -- see if there is a chest above the turtle
			    local bSuccess, tData = turtle.inspectUp()
			    if bSuccess and tData.name == "minecraft:chest" then
				   -- dump everything in slots 1-14 in the goodies chest
				   for i = 1, 14 do
					   turtle.select(i)
					   turtle.dropUp()
				   end
			    end
			    turtle.select(1)
			    while yrem ~= ypos do
					  turtle.down()
					  ypos = ypos - 1
			    end
			    if mission ~= 0 then -- if mission is not complete
				   -- mission = 2 -- it just finished dropping and returning
				   mission = 1
			    end
		    end
	  end
end
valithor #2
Posted 23 November 2014 - 05:17 PM
I made a vertical miner turtle program that works just like I want it to.

But the last time I ran it, it couldn't move down because of a slime directly underneath the turtle, but it thought it had. So it just spun in place forever and ever.

Perhaps I could add a section to the program to look for slimes below it and kill them, before trying to move down?

Here is the current program…

-snip

It is usually smart when doing stuff like this to make a function, which will try to move. If the turtle cant move, the funtion will then try to dig then try to attack. An example of this would be.

function forward()
  while not turtle.forward() do -- if the turtle moves right here it wont attack or dig
	turtle.dig()
	turtle.attack()
  end
end

You would call this in place of turtle.forward(), and would prevent the turtle from being stuck on mobs/blocks.

edit:
Seeing as you did not use any functions in your program I will make it a little clearer. You would put the code i provided somewhere above the while loop, and where you have turtle.forward() you would just put forward().
Edited on 23 November 2014 - 04:19 PM
KingofGamesYami #3
Posted 23 November 2014 - 05:34 PM
While valithor makes a good point, your stated problem is moving down, not forward. Simply do the same thing for down and up..


function down()
  while not turtle.down() do
    turtle.digDown()
    turtle.attackDown()
  end
end

See if you can properly construct an up function, based on this information.
TyCamden #4
Posted 23 November 2014 - 06:05 PM
I rewrote the program, but when it goes down, it is now skipping every other level.

Any idea why ?

code:


-- before running program, be sure...
--    coal is in slot 16
--    cobble in slot 15
--    put an actual chest ABOVE the turtle that will be on the mission (empty) (for the loot)
--    put an actual chest BEHIND the turtle that will be on the mission (with more coal in it)
function up()
  while not turtle.up() do
    turtle.digUp()
    turtle.attackUp()
  end
end
function down()
  while not turtle.down() do
    turtle.digDown()
    turtle.attackDown()
  end
end
ypos = 0 -- This tracks how far down turtle is from its starting position
facing = 0 -- This tracks direction turtle is facing 0=original-front 1=left 2=right 3=back
mission = 1 -- Current status of mission.
			   -- 0 means mission completed
			   -- 1 means operational mission, still running.
			   -- 2 means that it is time to drop off stuff then return to where u left off
			   -- 3 means that it is time to refuel
while mission ~= 0 do
	  FuelLeft = turtle.getFuelLevel() + 1
	  if FuelLeft < 65 then -- if there is less than 65 fuel in the turtle...
		 mission = 3
		 if turtle.getItemCount(16) > 0 then -- if there is at least 1 item in coal-slot 16...
		    turtle.select(16) -- choose slot 16 on turtle
		    turtle.refuel(1) -- refuel turtle with 1 item from slot 16
		    turtle.select(1) -- choose slot 1 on turtle (default?)
		    mission = 1
		 else
			 -- coal slot is empty so go back and get more fuel into slot 16
			 yrem = ypos -- remember ypos before returning for fuel
			 facrem = facing -- remember facing before returning for fuel
			 if ypos == 0 then -- you are back at start
			    -- get turtle facing the chest (backwards from original direction
			    if facing == 0 then -- facing forward
				   turtle.turnLeft() -- turn left
				   turtle.turnLeft() -- turn left
				   facing = 3
			    end
			    if facing == 1 then -- facing left
				   turtle.turnLeft() -- turn left
				   facing = 3
			    end
			    if facing == 2 then -- facing right
				   turtle.turnRight() -- turn right
				   facing = 3
			    end
			    -- see if fuel chest is empty or not and get more fuel
			    turtle.select(16) -- choose slot 16 on turtle
			    turtle.suck() -- suck fuel out of chest into slot 16 if possible
			    turtle.turnRight() -- turning turtle back towards facing the front
				   facing = 1
			    turtle.turnRight() -- finishing turning turtle to facing the front
				   facing = 0
			    turtle.refuel(1) -- refuel turtle with 1 item from slot 16
			    turtle.select(1) -- choose slot 1 on turtle (default?)
			    FuelLeft = turtle.getFuelLevel() + 1
			    if FuelLeft < 65 then -- still less than 65 fuel after refueling attempt
				   print "Not enough fuel to continue mission."
			    else
				    -- RETURN TO POSITION PRIOR TO NEEDING FUEL IF NECESSARY
				    while yrem ~= ypos do
					   down()
					   ypos = ypos - 1
				    end
				    while facrem ~= facing do
						  turtle.turnRight()
						  if facing == 0 then -- 0=original-front 1=left 2=right 3=back
							 facing = 2
						  else
							  if facing == 1 then
								 facing = 0
							  else
								  if facing == 2 then
									 facing = 3
								  else
									  -- facing = 3
									  facing = 1
								  end
							  end
						  end
				    end
				    mission = 1
			    end
			 else
				 -- move back up to start
				 while ypos<0 and ypos~=0 do
					   up()
					   ypos = ypos + 1
				 end
			 end
		 end
	  else  -- if there is NOT less than 65 fuel in the turtle...
		    if down() then -- it was able to move down
			   ypos = ypos - 1
		    else -- it cannot move down
			    -- find out what is below it and act accordingly
			    local bSuccess, tData = turtle.inspectDown()
			    if bSuccess and tData.name == "minecraft:chest" then
				   turtle.suckDown()
				   turtle.select(15)
				   turtle.placeDown()
				   turtle.select(1)
				   mission = 2 -- drop off all new stuff after grabbing a rare chest
			    else
				    if bSuccess and tData.name == "minecraft:bedrock" then -- bottom of the world
					   mission = 0
					   while ypos ~= 0 do
							 up()
							 ypos = ypos + 1
							 -- fill below turtle with cobble IF there is cobble in slot 15
							 cobcnt = turtle.getItemCount(15)
							 if cobcnt <1 then
							    for i = 1, 14 do
								    sltcnt = turtle.getItemCount(i)
								    if sltcnt > 0 then
									   wut = turtle.getItemDetail(i)
									   if wut.name == "minecraft:cobblestone" then
										  turtle.select(i)
										  turtle.transferTo(15)
										  turtle.select(1)
									   end
								    end
							    end
							 end
							 turtle.select(15)
							 turtle.placeDown()
							 turtle.select(1)
					   end
				    else
					    turtle.digDown()
					    down()
					    ypos = ypos - 1
				    end
			    end
		    end
		    if mission~=2 and mission~=0 then
			   -- seal any holes around this location (main concern: lava)
			   for i = 1, 4 do
				   if turtle.detect()=="false" then
					  -- there is a hole
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
					  turtle.turnLeft()
				   end
			   end
			   -- look around for goodies
			   flag = 0
			   for i = 1, 4 do
				   local bSuccess, tData = turtle.inspect()
				   if bSuccess and tData.name == "minecraft:stone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:cobblestone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:dirt" then
					  flag = 1
				   end
				   -- if the flag is still zero, it may be valuable
				   --  and just get rid of gravel
				   if flag == 0 then
					  turtle.dig()
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
				   end
				   turtle.turnLeft()
				   flag = 0
			   end
		    else
			    -- mission = 2 (or 0)
			    --    2 means that it is time to drop off stuff then return to where u left off
			    -- there is a chest ABOVE the turtle start position for the loot
			    yrem = ypos -- remember ypos before returning for fuel
			    while ypos ~= 0 do
					  up()
					  ypos = ypos + 1
			    end
			    -- top off slot 15 (cobble) to 64 items - if possible from goodies collected
			    cobb = turtle.getItemCount(15)
			    if cobb < 64 then
					  for i = 1, 14 do
						  ctslt = turtle.getItemCount(i)
						  if ctslt ~= 0 then
							 wut = turtle.getItemDetail(i)
							 if wut.name == "minecraft:cobblestone" then
							    turtle.select(i)
							    turtle.transferTo(15)
							    end
						  end
					  end
			    end
			    turtle.select(1)
			    -- see if there is a chest above the turtle
			    local bSuccess, tData = turtle.inspectUp()
			    if bSuccess and tData.name == "minecraft:chest" then
				   -- dump everything in slots 1-14 in the goodies chest
				   for i = 1, 14 do
					   turtle.select(i)
					   turtle.dropUp()
				   end
			    end
			    turtle.select(1)
			    while yrem ~= ypos do
					  down()
					  ypos = ypos - 1
			    end
			    if mission ~= 0 then -- if mission is not complete
				   -- mission = 2 -- it just finished dropping and returning
				   mission = 1
			    end
		    end
	  end
end
valithor #5
Posted 24 November 2014 - 12:02 AM
You need to make the two functions return true after the while loop. Right now you are running each one once in the if statement, but they don't return anything so it always goes to the else. Would post a example, but am posting this from my phone.


function down()
  while not turtle.down() do
    -- do stuff
  end
  return true -- after the turtle moves it returns true
end
Edited on 23 November 2014 - 11:25 PM
TyCamden #6
Posted 24 November 2014 - 12:15 AM
I don't know how to build this new idea into my existing functions because it is currently a "while not".

If anyone could post an amended version of my functions, I would appreciate it. Thank you.
valithor #7
Posted 24 November 2014 - 12:20 AM
I don't know how to build this new idea into my existing functions because it is currently a "while not".

If anyone could post an amended version of my functions, I would appreciate it. Thank you.

Oh sorry I meant to put while not turtle.down() do. As I said I am posting this from my phone, and it makes it slightly difficult.
deletedededed #8
Posted 24 November 2014 - 02:16 AM
I rewrote the program, but when it goes down, it is now skipping every other level.

Any idea why ?

code:

Your Code

-- before running program, be sure...
--	coal is in slot 16
--	cobble in slot 15
--	put an actual chest ABOVE the turtle that will be on the mission (empty) (for the loot)
--	put an actual chest BEHIND the turtle that will be on the mission (with more coal in it)
function up()
  while not turtle.up() do
	turtle.digUp()
	turtle.attackUp()
  end
end
function down()
  while not turtle.down() do
	turtle.digDown()
	turtle.attackDown()
  end
end
ypos = 0 -- This tracks how far down turtle is from its starting position
facing = 0 -- This tracks direction turtle is facing 0=original-front 1=left 2=right 3=back
mission = 1 -- Current status of mission.
			   -- 0 means mission completed
			   -- 1 means operational mission, still running.
			   -- 2 means that it is time to drop off stuff then return to where u left off
			   -- 3 means that it is time to refuel
while mission ~= 0 do
	  FuelLeft = turtle.getFuelLevel() + 1
	  if FuelLeft < 65 then -- if there is less than 65 fuel in the turtle...
		 mission = 3
		 if turtle.getItemCount(16) > 0 then -- if there is at least 1 item in coal-slot 16...
			turtle.select(16) -- choose slot 16 on turtle
			turtle.refuel(1) -- refuel turtle with 1 item from slot 16
			turtle.select(1) -- choose slot 1 on turtle (default?)
			mission = 1
		 else
			 -- coal slot is empty so go back and get more fuel into slot 16
			 yrem = ypos -- remember ypos before returning for fuel
			 facrem = facing -- remember facing before returning for fuel
			 if ypos == 0 then -- you are back at start
				-- get turtle facing the chest (backwards from original direction
				if facing == 0 then -- facing forward
				   turtle.turnLeft() -- turn left
				   turtle.turnLeft() -- turn left
				   facing = 3
				end
				if facing == 1 then -- facing left
				   turtle.turnLeft() -- turn left
				   facing = 3
				end
				if facing == 2 then -- facing right
				   turtle.turnRight() -- turn right
				   facing = 3
				end
				-- see if fuel chest is empty or not and get more fuel
				turtle.select(16) -- choose slot 16 on turtle
				turtle.suck() -- suck fuel out of chest into slot 16 if possible
				turtle.turnRight() -- turning turtle back towards facing the front
				   facing = 1
				turtle.turnRight() -- finishing turning turtle to facing the front
				   facing = 0
				turtle.refuel(1) -- refuel turtle with 1 item from slot 16
				turtle.select(1) -- choose slot 1 on turtle (default?)
				FuelLeft = turtle.getFuelLevel() + 1
				if FuelLeft < 65 then -- still less than 65 fuel after refueling attempt
				   print "Not enough fuel to continue mission."
				else
					-- RETURN TO POSITION PRIOR TO NEEDING FUEL IF NECESSARY
					while yrem ~= ypos do
					   down()
					   ypos = ypos - 1
					end
					while facrem ~= facing do
						  turtle.turnRight()
						  if facing == 0 then -- 0=original-front 1=left 2=right 3=back
							 facing = 2
						  else
							  if facing == 1 then
								 facing = 0
							  else
								  if facing == 2 then
									 facing = 3
								  else
									  -- facing = 3
									  facing = 1
								  end
							  end
						  end
					end
					mission = 1
				end
			 else
				 -- move back up to start
				 while ypos<0 and ypos~=0 do
					   up()
					   ypos = ypos + 1
				 end
			 end
		 end
	  else  -- if there is NOT less than 65 fuel in the turtle...
			if down() then -- it was able to move down
			   ypos = ypos - 1
			else -- it cannot move down
				-- find out what is below it and act accordingly
				local bSuccess, tData = turtle.inspectDown()
				if bSuccess and tData.name == "minecraft:chest" then
				   turtle.suckDown()
				   turtle.select(15)
				   turtle.placeDown()
				   turtle.select(1)
				   mission = 2 -- drop off all new stuff after grabbing a rare chest
				else
					if bSuccess and tData.name == "minecraft:bedrock" then -- bottom of the world
					   mission = 0
					   while ypos ~= 0 do
							 up()
							 ypos = ypos + 1
							 -- fill below turtle with cobble IF there is cobble in slot 15
							 cobcnt = turtle.getItemCount(15)
							 if cobcnt <1 then
								for i = 1, 14 do
									sltcnt = turtle.getItemCount(i)
									if sltcnt > 0 then
									   wut = turtle.getItemDetail(i)
									   if wut.name == "minecraft:cobblestone" then
										  turtle.select(i)
										  turtle.transferTo(15)
										  turtle.select(1)
									   end
									end
								end
							 end
							 turtle.select(15)
							 turtle.placeDown()
							 turtle.select(1)
					   end
					else
						turtle.digDown()
						down()
						ypos = ypos - 1
					end
				end
			end
			if mission~=2 and mission~=0 then
			   -- seal any holes around this location (main concern: lava)
			   for i = 1, 4 do
				   if turtle.detect()=="false" then
					  -- there is a hole
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
					  turtle.turnLeft()
				   end
			   end
			   -- look around for goodies
			   flag = 0
			   for i = 1, 4 do
				   local bSuccess, tData = turtle.inspect()
				   if bSuccess and tData.name == "minecraft:stone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:cobblestone" then
					  flag = 1
				   end
				   if bSuccess and tData.name == "minecraft:dirt" then
					  flag = 1
				   end
				   -- if the flag is still zero, it may be valuable
				   --  and just get rid of gravel
				   if flag == 0 then
					  turtle.dig()
					  turtle.select(15)
					  turtle.place()
					  turtle.select(1)
				   end
				   turtle.turnLeft()
				   flag = 0
			   end
			else
				-- mission = 2 (or 0)
				--	2 means that it is time to drop off stuff then return to where u left off
				-- there is a chest ABOVE the turtle start position for the loot
				yrem = ypos -- remember ypos before returning for fuel
				while ypos ~= 0 do
					  up()
					  ypos = ypos + 1
				end
				-- top off slot 15 (cobble) to 64 items - if possible from goodies collected
				cobb = turtle.getItemCount(15)
				if cobb < 64 then
					  for i = 1, 14 do
						  ctslt = turtle.getItemCount(i)
						  if ctslt ~= 0 then
							 wut = turtle.getItemDetail(i)
							 if wut.name == "minecraft:cobblestone" then
								turtle.select(i)
								turtle.transferTo(15)
								end
						  end
					  end
				end
				turtle.select(1)
				-- see if there is a chest above the turtle
				local bSuccess, tData = turtle.inspectUp()
				if bSuccess and tData.name == "minecraft:chest" then
				   -- dump everything in slots 1-14 in the goodies chest
				   for i = 1, 14 do
					   turtle.select(i)
					   turtle.dropUp()
				   end
				end
				turtle.select(1)
				while yrem ~= ypos do
					  down()
					  ypos = ypos - 1
				end
				if mission ~= 0 then -- if mission is not complete
				   -- mission = 2 -- it just finished dropping and returning
				   mission = 1
				end
			end
	  end
end
I can't be much help with this but for future reference, Spoilers are nice.

Edit: I forgot to actually write anything the first time :blink:/>
Edited on 24 November 2014 - 01:17 AM
KingofGamesYami #9
Posted 24 November 2014 - 03:25 AM
While what valithor pointed out is true, you don't want to use the down function in that part, as it would cause the turtle to mine anything in it's way without performing any checks on it.

The block to re-write:
Spoiler

                    if down() then -- it was able to move down
                           ypos = ypos - 1
                    else -- it cannot move down
                            -- find out what is below it and act accordingly
                            local bSuccess, tData = turtle.inspectDown()
                            if bSuccess and tData.name == "minecraft:chest" then
                                   turtle.suckDown()
                                   turtle.select(15)
                                   turtle.placeDown()
                                   turtle.select(1)
                                   mission = 2 -- drop off all new stuff after grabbing a rare chest
                            else
                                    if bSuccess and tData.name == "minecraft:bedrock" then -- bottom of the world
                                           mission = 0
                                           while ypos ~= 0 do
                                                         up()
                                                         ypos = ypos + 1
                                                         -- fill below turtle with cobble IF there is cobble in slot 15
                                                         cobcnt = turtle.getItemCount(15)
                                                         if cobcnt <1 then
                                                            for i = 1, 14 do
                                                                    sltcnt = turtle.getItemCount(i)
                                                                    if sltcnt > 0 then
                                                                           wut = turtle.getItemDetail(i)
                                                                           if wut.name == "minecraft:cobblestone" then
                                                                                  turtle.select(i)
                                                                                  turtle.transferTo(15)
                                                                                  turtle.select(1)
                                                                           end
                                                                    end
                                                            end
                                                         end
                                                         turtle.select(15)
                                                         turtle.placeDown()
                                                         turtle.select(1)
                                           end
                                    else
                                            turtle.digDown()
                                            down()
                                            ypos = ypos - 1
                                    end
                            end
                    end

My fix (along with a couple tweaks):
Spoiler

if turtle.down() then
  --#we could move
  ypos = ypos - 1
elseif turtle.detectDown() then
  --#it's a block
  local bSuccess, tData = turtle.inspectDown()
  if bSuccess and tData.name == "minecraft:chest" then
    --#found a chest
    turtle.suckDown()
    turtle.select(15)
    turtle.placeDown()
    turtle.select(1)
    mission = 2 -- drop off all new stuff after grabbing a rare chest
  elseif bSuccess and tData.name == "minecraft:bedrock" then
    --#oh noes! bedrock!
    mission = 0
    while ypos ~= 0 do
      up()
      ypos = ypos + 1
      -- fill below turtle with cobble IF there is cobble in slot 15
      cobcnt = turtle.getItemCount(15)
      if cobcnt < 1 then
        for i = 1, 14 do --#note: turtle.getItemDetail can be used on empty slots.
          wut = turtle.getItemDetail(i)
            if wut and wut.name == "minecraft:cobblestone" then
              turtle.select(i)
              turtle.transferTo(15)
              turtle.select(1)
            end
          end
        end
        turtle.select(15)
        turtle.placeDown()
        turtle.select(1)
      end
   else
     turtle.digDown()
     down()
     ypos = ypos - 1
   end
else
  --#it's an entity
  down()
  ypos = ypos - 1
end
TyCamden #10
Posted 24 November 2014 - 01:56 PM
Thank you everyone for your help. It's working :D/>