Posted 26 April 2015 - 03:08 AM
                I have thought of a mining program, that would strip mine, while looking for ores around him, and if he finds one, he mines it in recursive manner…
This is code responsible for checking if it is ore or not
If there is any existing program, I am sorry, but couldn't find any.
I have tried, but can't think in recursion… help or program is appreciated.
                
            This is code responsible for checking if it is ore or not
local success, data = turtle.inspect()
if success and string.find(string.lower(data.name),"ore") then
  print(data.name)  --  ore name (minecraft:redstone_ore, or something like that)
end
If there is any existing program, I am sorry, but couldn't find any.
I have tried, but can't think in recursion… help or program is appreciated.
function seek(ore,side)
  local name = string.find(string.lower(ore),":")
  name = string.sub(ore,name+1)
  print("Found " .. name)
  shell.run("refuel")
  if side=="up" then
	turtle.digUp()
	turtle.up()
  elseif side=="down" then
	turtle.digDown()
	turtle.down()
  else
	turtle.dig()
	turtle.forward()
  end
  try("down")
  turtle.back()
end
function try(side)
  if side=="down" then
	local success, data = turtle.inspect()
	if success and string.find(string.lower(data.name),"ore") then
	  seek(data.name)
	else
	  turtle.dig()
	end
	shell.run("refuel")
	turtle.forward()
  else
	local success, data = turtle.inspectUp()
	if success and string.find(string.lower(data.name),"ore") then
	  seek(data.name,"up")
	else
	  turtle.digUp()
	end
	shell.run("refuel")
	turtle.up()
  end
  turtle.turnRight()
  success, data = turtle.inspect()
  if success and string.find(string.lower(data.name),"ore") then
	seek(data.name)
  end
  turtle.turnLeft()
  turtle.turnLeft()
  success, data = turtle.inspect()
  if success and string.find(string.lower(data.name),"ore") then
	seek(data.name)
  end
  turtle.turnRight()
  if side=="down" then
	success, data = turtle.inspectDown()
  else
	success, data = turtle.inspectUp()
  end
  if success and string.find(string.lower(data.name),"ore") then
	seek(data.name,side)
  end
end
local left = tonumber(...)
local level = 0
if left == nil then
  print("How far should it try to dig?")
  left = tonumber(io.read())
end
while left > 0 do
  try("down")
  shell.run("refuel")
  turtle.up()
  try("up")
  shell.run("refuel")
  turtle.down()
  left = left -1
end
print("I am done")