How and why this is returning true?

var, var2 = "John", "324234" print(var \> var2)

returns true

Doesn’t it compare the character lenght? Can someone please explain before I go mad? :slight_smile:

Lua uses a character set known as ASCII.  Each character is assigned a numerical value.  The number characters are less than any of the letter characters.  A capital J is a value of 74.  A “1” is 49.  74 is > 49 thus the test is true.

Rob

Thanks for the explanation Rob. 

Were you trying to find which string is longer?  When you say  ‘compare the character length’ I am guessing maybe you mean the length of the string… that is the number of characters in each of those 2 strings.

try:

print( string.len(var) > string.len(var1) )

​hope this helps!

Cool, this really helped! Thanks!

Lua uses a character set known as ASCII.  Each character is assigned a numerical value.  The number characters are less than any of the letter characters.  A capital J is a value of 74.  A “1” is 49.  74 is > 49 thus the test is true.

Rob

Thanks for the explanation Rob. 

Were you trying to find which string is longer?  When you say  ‘compare the character length’ I am guessing maybe you mean the length of the string… that is the number of characters in each of those 2 strings.

try:

print( string.len(var) > string.len(var1) )

​hope this helps!

Cool, this really helped! Thanks!