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

Problem with read()

Started by oWave, 27 June 2013 - 01:37 PM
oWave #1
Posted 27 June 2013 - 03:37 PM
I have a little problem with the read() command

For testing, I made this:

print "1 = ?" --Answer is 1
input = read()
  if input == 1 then
	print "Yes"
  else
	print("No" .. input .. "isn't 1"
  end

If I then type in 1, it says "No 1 isn't 1"
I have no idea why.
Could somebody help me here?
GopherAtl #2
Posted 27 June 2013 - 03:53 PM
read always returns a string. Either compare input to a string, like "1", or pass input through tonumber() first, ex, local input=tonumber(read())
oWave #3
Posted 27 June 2013 - 04:06 PM
oww… ok
Didn't know that's a string.
Thanks
Apfeldstrudel #4
Posted 28 June 2013 - 10:16 AM
Or just quote the 1:P
0099 #5
Posted 30 June 2013 - 04:09 PM

if input == "1" then
or

input = tonumber(read())
because "1" isn't 1, but tonumber("1") == 1