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

[SOLVED] (Thanks to Bomb Bloke) Script wont do what it should do (problem with turtle.inspect)

Started by Julian, 08 July 2017 - 05:37 PM
Julian #1
Posted 08 July 2017 - 07:37 PM
So my code is:

shell.run("clear")
print("Working...")
turtle.select(1)
while true do
scs, block = turtle.inspect()
if scs == true then
  if block.name ~= "flowing_lava" or block.name ~= "lava" then
   turtle.dig()
   turtle.select(16)
   if turtle.compareDown() == false then
	turtle.turnRight()
	for f=1,16 do
	 turtle.select(f)
	 turtle.drop()
	end
	turtle.turnLeft()
   end
   turtle.select(1)
  else
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
   sleep(2)
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
  end
end
end
I use this code with something frrom botania (another mc mod) where it makes stone to ores and the turtle is in front of a stone generator with lava and water. Now sometimes the lava flows in front of the water so i have to send a redstone output to a dispenser to get the lava back in or out if that happens.

But this part:

if block.name ~= "flowing_lava" or block.name ~= "lava" then
doesnt really work, its always just keep switching to slot 1 and 16 but it should just do the redstone part there.

Btw i already changed the "or" to an "and" and i already switched the ~= to == and switched the redstone part with the other part (i also used "and" there)
Edited on 08 July 2017 - 11:18 PM
supernicejohn #2
Posted 08 July 2017 - 09:42 PM

if block.name ~= "flowing_lava" or block.name ~= "lava" then
Will wait for block.name to not be equal to "flowing_lava", for example, "lava", where the first condition (not equal to "flowing_lava") is true, and so it executes the first block of code rather than the second.

Solution would be to simply swap out "or" for "and" instead, which will hopefully produce intended behavior :)/>
Wojbie #3
Posted 08 July 2017 - 09:52 PM
Also turtle inspect returns name using modname:blockname method. So it should be minecraft:lawa and minecraft:flowing_lava.
Julian #4
Posted 08 July 2017 - 10:28 PM
my code is now:

shell.run("clear")
print("Working...")
turtle.select(1)
while true do
scs, block = turtle.inspect()
if scs == true then
  if block.name ~= "minecraft:flowing_lava" and block.name ~= "minecraft:lava" then
   turtle.dig()
   turtle.select(16)
   if turtle.compareDown() == false then
    turtle.turnRight()
    for f=1,16 do
	 turtle.select(f)
	 turtle.drop()
    end
    turtle.turnLeft()
   end
   turtle.select(1)
  else
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
   sleep(2)
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
  end
end
end
and it still wont work
Bomb Bloke #5
Posted 09 July 2017 - 12:44 AM
No Thermal Expansion? An Igneous Extruder's much better for this sort of thing.

Rather than switching slots and using compareDown (presumably against an air block?) to check whether something's in your last slot, you could just check if turtle.getItemCount(16) > 0. It'd likewise be faster to place the output chest above or below the turtle, so that it doesn't have to turn.

I believe some older versions of the mod do omit "minecraft" from the block strings. "if not block.name:find("lava") then" should work under any version.

If you're still having trouble, post example output when entering turtle.inspect() directly into the Lua console. If you're on an older version, you may need to pass the table through textutils.serialise() in order to read it.
Julian #6
Posted 09 July 2017 - 01:15 AM
An Igneous Extruder wouldnt the thing i want to but i was able to fix my code with your tips, thanks! My code looks like this now:

shell.run("clear")
print("Working...")
turtle.select(1)
while true do
scs, block = turtle.inspect()
if scs == true then
  if not block.name:find("flowing_lava") and not block.name:find("lava") then
   if not block.name:find("flowing_water") and not block.name:find("water") then
    turtle.dig()
    if turtle.getItemCount(16) > 0 then
	 for f=1,16 do
	  turtle.select(f)
	  turtle.dropDown()
	 end
    end
    turtle.select(1)
   end
  else
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
   sleep(2)
   redstone.setOutput("top",true)
   sleep(1)
   redstone.setOutput("top",false)
  end
end
end