355 posts
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)
295 posts
Location
In the TARDIS at an unknown place in time.
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.
56 posts
Location
Victoria, AUS
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.
355 posts
Posted 21 October 2012 - 07:00 AM
Wow, fast reactions!
Thanks guys, that helps a lot!
355 posts
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.
56 posts
Location
Victoria, AUS
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.
355 posts
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…
355 posts
Posted 21 October 2012 - 07:52 AM
Also…
turtle.forward()
doesnt seem to work..
Bug?
Nevermind, forgot that they need fuel!
2088 posts
Location
South Africa
Posted 21 October 2012 - 02:51 PM
Nevermind, forgot that they need fuel!
Lmao xD