AHK V2: Arrays of Arrays: is doc correct? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

AHK V2: Arrays of Arrays: is doc correct?

01 Jul 2018, 17:21

the content of column y of row x can be set using either of the methods below:

Code: Select all

table[x][y] := content  ; A
table[x, y] := content  ; B
If table[x] does not exist, A and B differ in two ways:
•A fails whereas B automatically creates an object and stores it in table[x].
If table[x] does not exist, I'm finding that both statements return the same error:
Error: No object to invoke.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: AHK V2: Arrays of Arrays: is doc correct?

01 Jul 2018, 19:13

from
https://autohotkey.com/v2/v2-changes.htm
An exception is thrown when any of the following failures occur (instead of ignoring the failure or producing an empty string):

...
x[y,z] fails due to x[y] containing a non-object value.
...

SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: AHK V2: Arrays of Arrays: is doc correct?

01 Jul 2018, 19:32

K thanks - hopefully someone will update the V2 doc
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: AHK V2: Arrays of Arrays: is doc correct?  Topic is solved

02 Jul 2018, 02:57

I'm finding that both statements return the same error
You found it wrong, it works as expected. My guess is you didn't do table := [] first.
x[y,z] fails due to x[y] containing a non-object value.
This fails in v1 too, but doesn't cause an exception. Not containing anything isn't the same as containing a non-object value. If you assign x[y] := 1, then x[y,z] := ... fails due to x[y] containing a non-object value.
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: AHK V2: Arrays of Arrays: is doc correct?

03 Jul 2018, 00:59

Helgef -
Thank you VERY MUCH for your post. It was extremely helpful for me.

For anyone else who got stuck where I was, this is what I needed to go through to understand what was going one:

Code: Select all

; y := x[2]             ; "Error:  No object to invoke" (i.e. "x" was not created as an object)

x :=[]                  ; create object "x"
y := x["y1"]            ; item/element "y1" doesn't exist; "y" set to empty

x[1] := 11              ; item "1" created
x["y","z"] := "..."     ; creates "object 'y' containing item 'z'" as an item in object "x"

xy := x["y"]            ; assigns object "y" from object "x"; "xy" is therefore an object

;x["y1"]["z"] := "..."  ; "Error:  No object to invoke" 
                        ; i.e. Item "z" can only be created if item "y1" is an object.
						; Item "y1" does not exist.
                        
x["y1"] := "..."        

;x["y1",z] := "..."     ; "Error:  Array is not multi-dimensional."
                        ; i.e. again, item "z" can only be created if item "y1" is an object.
						; Item "y1" is not an object; it has a value of "...".

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Pyper, RaptorX and 60 guests