nss Posted February 13, 2017 Posted February 13, 2017 (edited) Hi all. Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything. Here's the example: local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing? BTW, I haven't seen Autoit get updated since 2015; is it abandened or something? Any help/clarification appreciated. Edited February 14, 2017 by Melba23 Amended title
Subz Posted February 13, 2017 Posted February 13, 2017 This works for me: local $r[2] Enum $test1, $test2 $r[$test1]="hello" $r[$test2]="how are you" msgbox(64, $r[0], $r[1]) nss 1
InunoTaishou Posted February 13, 2017 Posted February 13, 2017 The reason it doesn't work is because AutoIt, currently, doesn't support maps (Which is what you're trying to do). You can assign/get a value using a string in the brackts ([]) because autoit will implicitly convert a string to 0 when it's expecting an integer but supplied a string. So what you really did was this local $r[2] $r[0]="hello" $r[0]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing? nss 1
nss Posted February 14, 2017 Author Posted February 14, 2017 Thanks much guys. Upon further testing, it seems that the [0] returns the last added element the way I did it. But then comes the question how would you dynamically loop through such arrays if you didn't know the string indexes? The enum variable way seems a bad idea (performance-wise) for big arrays, so is there another way? P.S., I'm not using the beta, I did once, and it would always scream at me that it is the beta, and it annoyed me.
InunoTaishou Posted February 14, 2017 Posted February 14, 2017 That's why I said "currently, doesn't support maps". If you're trying to loop through an array of unknown values you can use UBound to get the number of elements #include <Array.au3> Global $aArray[32] ; UBound - 1 to make it zero based For $i = 0 to UBound($aArray) - 1 $aArray[$i] = Random(0, 32, 1) Next _ArrayDisplay($aArray)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now