associate arrays refuse to work Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

associate arrays refuse to work

Post by Skrell » 24 Mar 2023, 22:12

All I'm trying to do is store a series of key:value pairs as hex:integer items. I understand an associate array can't use a simple hex or integer value as an a key or it'll interpret it as a regular array, so I'm trying to make the hex value into a string for use as a key. However, this ALWAYS returns a length of 0:

Code: Select all

      MouseGetPos, MX, MY, EWD_MouseWinHwnd      
      EWD_MouseWinStr := "hwnd" . EWD_MouseWinHwnd
      WinBackupXs[(EWD_MouseWinStr)] := EWD_WinX
      totalLen := WinBackupXs.length()
      FileAppend, %A_MM%/%A_DD%/%A_YYYY% @ %A_Hour%:%A_Min%:%A_Sec% - Make %EWD_MouseWinStr%:%EWD_WinX%:%totalLen% `n, C:\Users\vmb11\Desktop\log.txt

User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: associate arrays refuse to work

Post by Chunjee » 24 Mar 2023, 23:43

I would use .count() instead.


.length() docs: "Returns the length of a linear array."
but you don't have a linear array so it'll return zero most likely.

Code: Select all

msgbox % {-10: 0, -1: 0}.length() 
; => 0

msgbox % {-10: 0, -1: 0}.count() 
; => 2

Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: associate arrays refuse to work  Topic is solved

Post by Skrell » 25 Mar 2023, 10:13

Chunjee wrote:
24 Mar 2023, 23:43
I would use .count() instead.


.length() docs: "Returns the length of a linear array."
but you don't have a linear array so it'll return zero most likely.

Code: Select all

msgbox % {-10: 0, -1: 0}.length() 
; => 0

msgbox % {-10: 0, -1: 0}.count() 
; => 2
TYTYTYTYTYTY!

User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: associate arrays refuse to work

Post by Chunjee » 25 Mar 2023, 12:59

I would just make it match other popular languages but they did it the ahk way :think:

Post Reply

Return to “Ask for Help (v1)”