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

Comparing string to number, got number

Started by forrestdog2, 25 March 2013 - 03:24 PM
forrestdog2 #1
Posted 25 March 2013 - 04:24 PM
I'm trying to write a Guess My Number program and I get that error.

the code is a bit like this

guess = 0
local num = math.random(1,100)
//some prints//
guess = read()
while guess ~= num do
if guess < num then
print "Too low!
break
else
print "Too high!"
break
end
end
theoriginalbit #2
Posted 25 March 2013 - 04:26 PM
You need to use tonumber to turn the string into a number.

guess = tonumber( read() )