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

Help needed with "Checking block"

Started by Tjakka5, 21 October 2012 - 04:53 AM
Tjakka5 #1
Posted 21 October 2012 - 06:53 AM
Hello everyone.

Im currently trying to use turtle.compareTo(9) to see if a block is cobblestone, or not.
However, it returns a boolean, and I want to save it as a string.
If this didnt make sense at all, here is my code that doesnt work:



local currentBlock
local trueOrFalse

trueOrFalse = turtle.compareTo(9)
if trueOrFalse == "true" then
currentBlock = cobblestone
end

print('" ..currentBlock)
brett122798 #2
Posted 21 October 2012 - 06:56 AM
The first two lines of code are pointless and will give you an error.

EDIT: Here's what your code should look like:


trueOrFalse = turtle.compareTo(9)
if trueOrFalse == true then
currentBlock = "cobblestone"
end

print(currentBlock)

EDIT #2: Well, I suppose you can turn the boolean into a string like what the guy below me did.
chiloxsan #3
Posted 21 October 2012 - 06:58 AM
Simply change

trueOrFalse = turtle.compareTo(9)
to

trueOrFalse = tostring(turtle.compareTo(9))

Also, try to use code tags when posting on the forums. It's the <> icon next to the picture in the post editor.
Tjakka5 #4
Posted 21 October 2012 - 07:00 AM
Wow, fast reactions!

Thanks guys, that helps a lot!
Tjakka5 #5
Posted 21 October 2012 - 07:11 AM
Thanks to what I learned, I was able to make this program that fits for what I want to do:


local currentBlock
local trueOrFalse
trueOrFalse = tostring(turtle.compareTo(9))
if trueOrFalse = "true" then
  currentBlock = "cobblestone"
end
print("" ..currentBlock)

Ofcourse, if it aint cobblestone, it will get an error, I tought of that, but its not included in above.
chiloxsan #6
Posted 21 October 2012 - 07:14 AM
Thanks to what I learned, I was able to make this program that fits for what I want to do:


local currentBlock
local trueOrFalse
trueOrFalse = tostring(turtle.compareTo(9))
if trueOrFalse = "true" then
  currentBlock = "cobblestone"
end
print("" ..currentBlock)

Ofcourse, if it aint cobblestone, it will get an error, I tought of that, but its not included in above.

I do highly recommend that if you are only using your trueOrFalse variable for comparison, that you do not convert to string and instead use

trueOrFalse = turtle.compareTo(9)
if trueOrFalse == true then

EDIT: Accidentally a word.
Tjakka5 #7
Posted 21 October 2012 - 07:26 AM
Thanks to what I learned, I was able to make this program that fits for what I want to do:


local currentBlock
local trueOrFalse
trueOrFalse = tostring(turtle.compareTo(9))
if trueOrFalse = "true" then
  currentBlock = "cobblestone"
end
print("" ..currentBlock)

Ofcourse, if it aint cobblestone, it will get an error, I tought of that, but its not included in above.

I do highly recommend that if you are only using your trueOrFalse variable for comparison, that you do not convert to string and instead use

trueOrFalse = turtle.compareTo(9)
if trueOrFalse == true then

EDIT: Accidentally a word.

But as of the fact that I'm not that good at CC, and 1 tiny problem can break your code, I prefer to do it big, simple, and slow, so you can see whats going wrong.

Btw, copying and pasting my code 8 times, only with 2 differences…
…I should use a function…
Tjakka5 #8
Posted 21 October 2012 - 07:52 AM
Also…


turtle.forward()

doesnt seem to work..

Bug?

Nevermind, forgot that they need fuel!
remiX #9
Posted 21 October 2012 - 02:51 PM
Nevermind, forgot that they need fuel!

Lmao xD