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

Need Help For a Tiny Program

Started by Elec11, 25 December 2012 - 10:25 AM
Elec11 #1
Posted 25 December 2012 - 11:25 AM
so i wanted to make a short mineing program but i cant get it to work


local input = read()
fuellevel = turtle.getFuelLevel()

if fuellevel<input
then
print("need refuel")
else
Print("Mineing")
--Function goes here
end
when I test it it says


mine: 5:  attempt to compare sting with
number expected, got string

im doing something wrong but what, please help,
Luanub #2
Posted 25 December 2012 - 11:31 AM
read() outputs a string and turtle.getFuelLevel() outputs a number, the types need to match for you to compare them. Convert the read output to a number by doing this

local input = tonumber(read())
NDFJay #3
Posted 25 December 2012 - 11:32 AM
try


local input = read()
fuellevel = turtle.getFuelLevel()

if fuellevel<tonumber(input)
then
print("need refuel")
else
Print("Mineing")
--Function goes here
end
[color=#000088]
jag #4
Posted 25 December 2012 - 11:36 AM

mine: 5:  attempt to compare sting with
number expected, got string
Compare sting with number
Either you spelled wrong or the error message was derpy :P/>
Elec11 #5
Posted 25 December 2012 - 11:41 AM
thanks Lua Nub
works like a charm