[Functions] _ Function modifying Object sent as Parameter (Bug?) Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User
Posts: 225
Joined: 26 Jun 2017, 08:12

[Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 21:09

Hi,

In the example below, the "f()" function modifies the "x" object sent as parameter when it is called!

Is this a bug?

Code: Select all

x := []
x["Test"] := "xxxxxxx"

f(x)

msgbox, % x["Test"]
;returns "yyyyyyyyyy"
;it should return "xxxxxxx" instead!
;Is this a bug?


f(Options)	;___________ f (Function) ____________
{
Options["Test"] := "yyyyyyyyyy"
}
Partial Solution:

Code: Select all

x := []
x["Test"] := "xxxxxxx - script"

f(x)

msgbox, % x["Test"]


f(Options)	;___________ f (Function) ____________
{
Options := Options.Clone()
;"Clone()", Returns a shallow (not always a 100% clone???) copy of the object.
;"Clone()" creates a new object from the object referenced by "x" variable!
;then, "Options" variable will reference that newly created/cloned object!

Options["Test"] := "yyyyyyyyyy - function"

msgbox, % Options["Test"]
}
Last edited by User on 20 Jul 2018, 23:18, edited 1 time in total.
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 21:24

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User
Posts: 225
Joined: 26 Jun 2017, 08:12

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 22:05

Do you happen to know how to create\clone a new object from the object referenced by a variable?
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)  Topic is solved

20 Jul 2018, 22:16

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User
Posts: 225
Joined: 26 Jun 2017, 08:12

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 22:23

Sorry about my ignorance related to this but, "Returns a shallow copy of the object", that "shallow" what does it mean in this context?

I see no further explanations from the link!
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 22:28

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User
Posts: 225
Joined: 26 Jun 2017, 08:12

Re: [Functions] _ Function modifying Object sent as Parameter (Bug?)

20 Jul 2018, 22:43

Well, I will mark "Object.Clone()" as a solution for this! (A "shallow" solution, I may say!)

Thanks for helping!

(Obs:) I updated the main post of this thread with a partial solution!

Return to “Ask For Help”

Who is online

Users browsing this forum: decs, Google [Bot], pdi, SAbboushi, tm6464 and 21 guests