Wouldn't that check if the fuel level is equal to the variable named unlimited which doesn't exist?
No.
turtle.getFuelLevel() == unlimited -- this compares the fuel level to the contents of the variable "unlimited"
turtle.getFuelLevel() == "unlimited" -- this compares the fuel level to the string "unlimited".
By researching I found out that you can use
if turtle.getFuelLevel == "unlimited" then
--code
end
So now I have a problem. If I try to use
if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() > 10 then
--code
end
and the fuel level
is unlimited then it will error, saying that I'm trying to compare a string with a number(which I am if the fuel level is unlimited). However if the fuel level
is not unlimited then it will error when I try to compare the fuel level with "unlimited". How do I fix this?
For one thing, you need the brackets after turtle.getFuelLevel.
turtle.getFuelLevel == "unlimited" -- this is always false unless things are seriously screwed up, because turtle.getFuelLevel is a function, not as tring.
turtle.getFuelLevel() == "unlimited" -- this is what you want
Lua will have no problem comparing a number to a string - it'll just tell you they aren't equal, like you'd expect.
123 == "unlimited" -- this is false, it doesn't raise an error
Also, with "or", if the left side is true then it won't bother running the right side:
123 < "hello" -- this raises an error
1+1 == 2 or 123 < "hello" -- this does not, since Lua stops before the second part
turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() > 10 -- so this is fine too