Is this a bug? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
eqv
Posts: 66
Joined: 18 Sep 2018, 22:17

Is this a bug?

19 Mar 2019, 11:00

As I am not sure if it is a bug, so I publish it in the "Ask For Help" section.

Why does the array "f" continue to increase in size (line 18)?, which causes an eternal loop (line 16):

Code: Select all

a:="FILE.FOLDER , FILE , FOLDER * REPLACE , JOIN * IGNORE , OVERWRITE , BOTH * NEED.PATH , AUTO.PATH"

b:=StrSplit(a," * "), c:=[]
For i, v in b
c[i]:=StrSplit(v," , ")

l:=c.Length(), d:=[], d:=c[l], f:=[]

;; ·····························································
For m, x in c
{
	j:=0, f:=d
	For w, w in c[l-m]
	{
		Msgbox % "A"
		For i, v in f
		{
		Msgbox % "C: " f.Length()
		d[j+i]:=w " * " v
		}
		Msgbox % "B"

		j:=d.Length()
		Loop, % j
		Msgbox % d[A_Index]

	}
	Msgbox % "D"
}
;; ·····························································

Loop, % d.Length()
Msgbox % d[A_Index]
If I remove line 23 ("j:=d.Length()"), the loop ends; but I do not understand what relationship it has with the array "f".

Thanks in advance.
just me
Posts: 7403
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Is this a bug?  Topic is solved

19 Mar 2019, 11:23

Code: Select all

For m, x in c
{
	j:=0, f:=d ; <<<<<<<<<<
	...
Because the variables f and d hold references to the same object. Each change to c also changes f.
eqv
Posts: 66
Joined: 18 Sep 2018, 22:17

Re: Is this a bug?

19 Mar 2019, 11:52

just me wrote:
19 Mar 2019, 11:23
Because the variables f and d hold references to the same object. Each change to c also changes f.
Thank you!, I didn't know that setting Var:=Array was a reference; I used to believe that it create another array.

→ So the solution was just apply Var:=[Array*], to create a new array.

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, Bing [Bot], plautus and 37 guests