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

Ability to see(turtle)

Started by Jarle212, 17 May 2013 - 05:53 PM
Jarle212 #1
Posted 17 May 2013 - 07:53 PM
If you ever wanted your turtle to see a bit. There is a method to make the turtle able to see whether a block is transparant or not, by using redstone logic

Turtle code:

rs.setOutput(side,true)
isSolid = rs.getInput(side)
if isSolid then
  --Do stuff
end
Dlcruz129 #2
Posted 17 May 2013 - 08:15 PM
Pretty neat little trick.
Jarle212 #3
Posted 17 May 2013 - 08:38 PM
Thank you
M4sh3dP0t4t03 #4
Posted 18 May 2013 - 01:31 AM
Looks nice! But I would like it more as a function:

function isSolid()
rs.setOutput(side,true)
local issolid = rs.getInput(side)
rs.setOutput(side, false)
return issolid
end
if isSolid() then
  --Do stuff
end
Note that I just coded that quickly in my browser and didn't tested it so I can't guarantee that it works
Orwell #5
Posted 18 May 2013 - 11:46 AM
Looks nice! But I would like it more as a function:

function isSolid()
rs.setOutput(side,true)
local issolid = rs.getInput(side)
rs.setOutput(side, false)
return issolid
end
if isSolid() then
  --Do stuff
end
Note that I just coded that quickly in my browser and didn't tested it so I can't guarantee that it works

If you put this in a function, you'd better pass the 'side' variable as argument:

function isSolid(side)
  rs.setOutput(side,true)
  local isSolid = rs.getInput(side)
  rs.setOutput(side, false)
  return isSolid
end
if isSolid('left') then
  --Do stuff
end

But really, making a function for this nifty snippet is the obvious part.
Engineer #6
Posted 18 May 2013 - 11:49 AM
I really like this! It can help in certain environments!
M4sh3dP0t4t03 #7
Posted 18 May 2013 - 11:56 AM
But it doesn't excactly tell if a block is solid: if you use redstone it says it is solid, but redstone isn't solid
superaxander #8
Posted 18 May 2013 - 12:15 PM
I love this!
Orwell #9
Posted 18 May 2013 - 12:15 PM
Redstone dust is obviously the only exception as it always conducts redstone power. But you rarely encounter redstone dust in the wild.
superaxander #10
Posted 18 May 2013 - 12:43 PM
This doesn't work if the block is already powered by a different thing like a lever
Engineer #11
Posted 18 May 2013 - 12:55 PM
This doesn't work if the block is already powered by a different thing like a lever
Of course not, because it can transmit redstone then! :D/>
So it is a solid block! :P/>
superaxander #12
Posted 18 May 2013 - 01:22 PM
oh haha
superaxander #13
Posted 18 May 2013 - 01:31 PM
Hmm glass and glowstone won't work either or do we count them as non-solid
Orwell #14
Posted 18 May 2013 - 01:48 PM
Hmm glass and glowstone won't work either or do we count them as non-solid
Technically they are solid. I think this snippet actually returns true for non-transparent blocks.
Jarle212 #15
Posted 18 May 2013 - 03:54 PM
Blocks like: glass, water, rails, half-slabs, leves. etc. Counts as transparent and will return false, other type of blocks will give true if anyone was a bit confuced :)/>
M4sh3dP0t4t03 #16
Posted 18 May 2013 - 03:59 PM
redstone isnt the only exception, redstone torches/levers and some other stuff can even give multiple results depending on the state of them
Orwell #17
Posted 18 May 2013 - 04:11 PM
redstone isnt the only exception, redstone torches/levers and some other stuff can even give multiple results depending on the state of them
Tricks like this (and most others) are only useful in natural or controlled environments.

This reminds me of another trick I discovered once. It's a method to detect if a block in front of the turtle is water or not (without a bucket, but with a mining turtle):

function isWater()
  return not turtle.detect() and turtle.dig()
end
This worked at least with CC 1.33. I haven't tested it since.
Engineer #18
Posted 18 May 2013 - 04:26 PM
-snip-
The snipper works beautifully. I have just tested it :P/>
Thank you!