minimal illustration code:
Code: Select all
numstr := "01"
array := []
array.Push(numstr)
msgbox % array[1]
If (array[1] = numstr)
{}
array.Push(numstr)
msgbox % array[2]
msgbox % array[1]
Code: Select all
numstr := "01"
array := []
array.Push(numstr)
msgbox % array[1]
If (array[1] = numstr)
{}
array.Push(numstr)
msgbox % array[2]
msgbox % array[1]
You can work around by doing x.push(y "")= wrote: If both inputs are numbers or numeric strings, they are compared numerically
[...]
Note: In AutoHotkey v1, a quoted string (or the result of concatenating with a quoted string) is never considered numeric when used directly in an expression.
Code: Select all
numstr := """01"""
array := []
array.Push(numstr)
if (array[1] == numstr)
{
array.Push(numstr)
msgbox % "numstr " numstr " array[1] " array[1] " array[2] " array[2]
}
Thank you! I think I got the point:
Code: Select all
numstr := "01" ; numstr contains only a string "01" at first
anothernumstr := "2"
array := []
array.Push(numstr) ; "01" is pushed for it is the only choice
If (numstr = anothernumstr) ; but now numstr contains a number 1, too[1]
{}
array.Push(numstr) ; 1 as the preferred one over "01" is pushed[2]
msgbox % array[2] ; 1
msgbox % array[1] ; 01
So it is NOT a bug. My bad[1] In effect, a variable can contain both a string and a number simultaneously.
[2] ... but if a variable contains both a number and a string, is it number, or is it a string? This ambiguity causes unexpected behavior in at least two cases: ... Objects don't have the capability to store both a number and a string as a key or value. Since numbers are more memory-efficient, if a variable has both, the number is used.