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

How do I get a turtle function to return false?

Started by Edam Bythemine, 15 September 2012 - 11:52 PM
Edam Bythemine #1
Posted 16 September 2012 - 01:52 AM
I'm using this code and every variant of it that I know, and it returns true no matter what constant I change. Could it be a bug?


turtle.detect()
if true then
print("true")
end
if false then
print("false")
end

The compare function is the same.

—-Edit:
Thanks CastleMan2000.
CastleMan2000 #2
Posted 16 September 2012 - 01:56 AM
That won't work because turtle.detect() would need to be in the if statements, or saved into a variable.


local detectBlock = turtle.detect()
if detectBlock == true then
print("true")
end
if detectBlock false then
print("false")
end

Or


if turtle.detect() then
print("true")
end
if not turtle.detect() then
print("false")
end

Same with turtle.compare().
Grim Reaper #3
Posted 16 September 2012 - 02:48 AM
Since turtle.detect() and turtle.compare() return a value, that you don't handle, you have no record of it in memory. True and false are constants, so when you check if either of them are themselves the conditional will be true.
CastleMan2000 #4
Posted 16 September 2012 - 03:27 AM
You're welcome. :)/>/>
Cloudy #5
Posted 16 September 2012 - 09:18 AM
Even better:
if turtle.detect() then
  print("true")
else
  print("false")
end