Jump to content




How do I get a turtle function to return false?

turtle api help

4 replies to this topic

#1 Edam Bythemine

  • New Members
  • 2 posts

Posted 16 September 2012 - 12: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.

#2 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 16 September 2012 - 12: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().

#3 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 16 September 2012 - 01: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.

#4 CastleMan2000

  • Members
  • 195 posts
  • LocationThe trashcan where all Undertale trash is

Posted 16 September 2012 - 02:27 AM

You're welcome. :)/>

#5 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 16 September 2012 - 08:18 AM

Even better:
if turtle.detect() then
  print("true")
else
  print("false")
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users