arrays/objects being overwritten when I don't want to Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

arrays/objects being overwritten when I don't want to

16 Aug 2018, 14:14

I have been running into this issue A LOT and its really pissing me of. Please help me, Why does this happen and how can I avoid this

Code: Select all

object := {A:1, B:2}
thing := object
thing["A"] := 2

array := [1, 2]
thing2 := array
thing2[1] := 2
msgbox % object["A"] . ", " . array[1] ;<both return 2 but I want them to return 1
return
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: arrays/objects being overwritten when I don't want to

16 Aug 2018, 14:31

Flipeador wrote:Related: https://autohotkey.com/boards/viewtopic ... 7&p=229505.
Current behavior is fine. You must clone the object.
Ah ok. So it should look like this

Code: Select all

object := {A:1, B:2}
thing := object.clone()
thing["A"] := 2

array := [1, 2]
thing2 := array.clone()
thing2[1] := 2
msgbox % object["A"] . ", " . array[1]
which seems to work. Thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, demon740, mapcarter and 304 guests