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

Turtle compare

Started by Obsidia, 04 January 2016 - 02:11 PM
Obsidia #1
Posted 04 January 2016 - 03:11 PM
I'm currently testing around with the compare command but I cant get it working properly.

Let's say I want it to check if there is redstone in front of it.

I got a turtle with 1 Redstone in slot 1.

The program I made looks like this:


if turtle.compare(1) == true then
	 print("There is redstone in front of me!")
  else
	 print("There is no redstone!")
end


It would always tell me "There is no redstone!" no matter what I place in front of it.

So I tried it with compareTo


if turtle.compareTo(1) == true then
	 print("There is redstone in front of me!")
  else
	 print("There is no redstone!")
end

This one would always say there is redstone in front of him even if there is no block at all.

What am I doing wrong?
KingofGamesYami #2
Posted 04 January 2016 - 04:10 PM
turtle.compareTo compares the currently selected slot the the slot number you give it. I would assume you have slot 1 selected, and are comparing it to slot 1. Obviously the stuff in slot 1 will always be the stuff in slot 1.

turtle.compare is finicky. I'd assume you're using redstone dust; redstone dust placed isn't the same as redstone dust in your hand. It's similar to water or lava, flowing lava is different from still lava, and both of those are different than the lava bucket in your inventory.
Obsidia #3
Posted 04 January 2016 - 04:36 PM
turtle.compareTo compares the currently selected slot the the slot number you give it. I would assume you have slot 1 selected, and are comparing it to slot 1. Obviously the stuff in slot 1 will always be the stuff in slot 1.

turtle.compare is finicky. I'd assume you're using redstone dust; redstone dust placed isn't the same as redstone dust in your hand. It's similar to water or lava, flowing lava is different from still lava, and both of those are different than the lava bucket in your inventory.

Tried it with dirt aswell and I didnt work either..
Should it?
KingofGamesYami #4
Posted 04 January 2016 - 04:47 PM
Try with sand. Sand doesn't change when you place it.

Dirt should work, unless it's turned into grassy dirt (umm… Can't remember the exact name right now)
Mr_Programmer #5
Posted 04 January 2016 - 06:56 PM
turtle.compareTo compares the currently selected slot the the slot number you give it. I would assume you have slot 1 selected, and are comparing it to slot 1. Obviously the stuff in slot 1 will always be the stuff in slot 1.

turtle.compare is finicky. I'd assume you're using redstone dust; redstone dust placed isn't the same as redstone dust in your hand. It's similar to water or lava, flowing lava is different from still lava, and both of those are different than the lava bucket in your inventory.

Tried it with dirt aswell and I didnt work either..
Should it?

You could try and make the turtle inspect whats in front and then compair it to slot 1 or what ever slot you wanted it to be, code would look somthing like this…

local check, infront = turtle.inspect() --# will get the block name and the metadata
  if check and infront.name == "minecraft:redstone_wire" then --#infront.name comes back to what ever is infront so for dirt it would be "minecraft:dirt"
	 local data =  turtle.getItemDetail(1) --# will get the item name, value and damage in the selected slot
	   if data.name == "minecraft:redstone" then
		 print("REDSTONE")
	   else
		 print("NOT REDSTONE")
	   end
  else
	print("block infront isnt redstone")
  end

There might be a better way but that is just a fix for it, it should work!
Edited on 04 January 2016 - 09:00 PM