16 posts
Posted 03 February 2014 - 05:26 AM
I've created a program that tests your memory span. It's not that good while it's still in development.
http://pastebin.com/2sBypZJPThe only problem is that when I see the numbers right, typing in the number identifies it as wrong. Some program modifications easily say they are the same number, but the result when checking it is "equal" is always false (or true in "not equal"). They are also pure numbers, and are not strings. Is there a reason this is happening?
286 posts
Location
United States
Posted 03 February 2014 - 05:32 AM
The problem is in the io.read() function you are using. It is reading in as a string, rather than a number, You could type convert it to a number before doing the test:
inum = tonumber(io.read())
Try that.
16 posts
Posted 03 February 2014 - 05:35 AM
The problem is in the io.read() function you are using. It is reading in as a string, rather than a number, You could type convert it to a number before doing the test:
inum = tonumber(io.read())
Try that.
Strange, it works. I wonder why? It would have did an error if you tried to compare a string with a number, and the "string" itself can be manipulated like a number…
286 posts
Location
United States
Posted 03 February 2014 - 05:38 AM
I'm just not sure if a number == string comparison will come out true. I shut down for the evening, otherwise I would test my theory.
Did you figure out if this was the problem??
16 posts
Posted 03 February 2014 - 05:42 AM
I'm just not sure if a number == string comparison will come out true. I shut down for the evening, otherwise I would test my theory.
Did you figure out if this was the problem??
I could hardly recall, but I remember coming here with a similar problem…
And no, not at all.
286 posts
Location
United States
Posted 03 February 2014 - 05:44 AM
So you are still having the problem??
286 posts
Location
United States
Posted 03 February 2014 - 05:53 AM
Okay. I just confirmed that my solution worked.
You must do a tonumber(read()) or tonumber(io.read())
7083 posts
Location
Tasmania (AU)
Posted 03 February 2014 - 05:56 AM
Under Lua, you can perform some mathematical operations on strings. Strange but true.
286 posts
Location
United States
Posted 03 February 2014 - 05:58 AM
Under Lua, you can perform some mathematical operations on strings. Strange but true.
And you can concatenate numbers. For example:
a = 4
b =67
print( a .. b )
--result 467
Edited on 03 February 2014 - 04:59 AM