Jump to content




Problem with read()


  • You cannot reply to this topic
4 replies to this topic

#1 oWave

  • Members
  • 23 posts

Posted 27 June 2013 - 02: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?

#2 GopherAtl

  • Members
  • 888 posts

Posted 27 June 2013 - 02: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())

#3 oWave

  • Members
  • 23 posts

Posted 27 June 2013 - 03:06 PM

oww... ok
Didn't know that's a string.
Thanks

#4 Apfeldstrudel

  • Members
  • 161 posts

Posted 28 June 2013 - 09:16 AM

Or just quote the 1:P

#5 0099

  • Members
  • 52 posts

Posted 30 June 2013 - 03:09 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users