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

How to use the turtle.compare function.

Started by zedekblue, 17 May 2013 - 11:35 PM
zedekblue #1
Posted 18 May 2013 - 01:35 AM
I've tried a couple different things to try and figure out how I would use this turtle.compare() thing, but I can't figure it out.

This doesn't work:

a = turtle.compare()
if (a == true) then
  print("Hi")
end

Nor does this, whether I write it as turtle.compare() or turtle.compare, true or "true":

if (turtle.compare == true) then
  print("Hi")
end

I even tried:

if (turtle.compare) then
  print("Hi")
end

During my experience with Java I figured the first example could work, but maybe I just wasn't using the variable a correctly. (Lua confuses me after I've done Java coding for so long. Lua skips over so many convenient details in the code language, I just never know what's going to happen.)
I've tried looking over code from some other programs I've grabbed from the forum, but everybody seems to do things so minimalistically with their coding, I just can't figure out how to apply any of it differently.
Help is appreciated! Thanks!
Shnupbups #2
Posted 18 May 2013 - 01:37 AM
turtle.compare() compares the block in front of the turtle to the block in the current inventory slot of the turtle.
For your code, use:

if turtle.compare() then
  print("Hi")
end
zedekblue #3
Posted 18 May 2013 - 01:44 AM
turtle.compare() compares the block in front of the turtle to the block in the current inventory slot of the turtle.
For your code, use:

if turtle.compare() then
  print("Hi")
end

Thanks much! Works like a charm.