Jump to content




turtle.inspect() mining

turtle api

4 replies to this topic

#1 Games_Arsenal96

  • Members
  • 4 posts
  • LocationSlidell, Louisianna

Posted 11 May 2017 - 08:39 AM

I am trying to currently code a working efficient mine straight down, but I can't get the code working for the block blacklists

--Once the code starts working I will add a fuel check
local b=0
local ignore={"minecraft:dirt","minecraft:stone","minecraft:cobblestone","minecraft:gravel","minecraft:sand"}
local function valuable()
success,data=turtle.inspect()
for k,v in pairs(ignore) do
  if v~=data.name then
   return true
  else
   return false
  end
end
end
local function checkSurroundings()
for I=1,4 do
  if valuable() then
   turtle.dig()
  end
  turtle.turnLeft()
end
end
for I=1,2 do
turtle.digDown()
turtle.down()
b=b+1
end
turtle.select(15)
turtle.placeUp() --Place cobblestone over entry hole
turtle.select(1)
while true do
turtle.digDown()
if turtle.down() then
  b=b+1
else
  for I=1,b do
   b=b-1
  end
end
checkSurroundings()

end

Can you amazing people help me?

Minecraft version: 1.7.10 (Just incase the mod changed in versions)

#2 Lupus590

  • Members
  • 2,007 posts
  • LocationUK

Posted 11 May 2017 - 03:45 PM

local function valuable()
success,data=turtle.inspect()
for k,v in pairs(ignore) do
  if v~=data.name then
   --# don't return, let the loop continue
  else
	 return false
  end
end
return true --# loop ended,
end

there is a more efficient way to do this though
local ignore={["minecraft:dirt"] = true,["minecraft:stone"] = true,["minecraft:cobblestone"] = true,["minecraft:gravel"] = true,["minecraft:sand"] = true}
--# set the ignores as the keys, then for quick access trick later
local function valuable()
success,data=turtle.inspect()
  if ignore[data.name] then --# quick access trick: we have the name of the block now, if it's in the list we will get true for the if
   return false
  else
   return true
  end
end


Edited by Lupus590, 11 May 2017 - 03:46 PM.


#3 Games_Arsenal96

  • Members
  • 4 posts
  • LocationSlidell, Louisianna

Posted 11 May 2017 - 06:16 PM

Oh I see it only went through the iterator once because it returned a value?

#4 Lupus590

  • Members
  • 2,007 posts
  • LocationUK

Posted 11 May 2017 - 08:16 PM

View PostGames_Arsenal96, on 11 May 2017 - 06:16 PM, said:

Oh I see it only went through the iterator once because it returned a value?

correct

#5 Games_Arsenal96

  • Members
  • 4 posts
  • LocationSlidell, Louisianna

Posted 11 May 2017 - 08:23 PM

I am trying to make the same code Ben did for his lets play of ComputerCraft challenge but to use inspect instead of certain blocks in slots?

I got it working now I just need to work on the fuel check





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users