Jump to content

possible bug with arrays [NOT]


nss
 Share

Recommended Posts

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 by Melba23
Amended title
Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...