Jump to content

Recommended Posts

Posted (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 by Melba23
Amended title
Posted

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?

 

Posted

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.

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
×
×
  • Create New...