# Perspective array custom properties

**URL:** <https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 6, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306 "2023-01-06T15:27:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [January 6, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/1 "2023-01-06T15:27:36Z")

</div>

I wish someone could help me understand what is happening in this simplified sample code here. I have an array, arr0, defined as a custom property (on view, root, etc. same result), read it to local arr1, and modify one of the elements of the local array, var0, but the results do not make any sense.  
This only happens with array. I usually hesitate to jump and call something a 'bug', but it seems to be it.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9a00c02bfdbb1ed0e37ca5ad3633128c743136fa.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 6, 2023, 5:02pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/2 "2023-01-06T17:02:15Z")

</div>

`arr1 = self.view.custom.arr0` is not making a copy of that `arr0` array - it is essentially saying "For all intents and purposes, I am the same thing as `arr0`."

So when you modify the value of the internal object (`var0`), the in-memory value which changes is the value referened by both `arr1` AND `self.view.custom.arr0[1].var0`.

It's a weird behavior of Python that can surprise people more use to Java or C. [This site](https://realpython.com/pointers-in-python/#:~:text=In%20memory%2C%20you%20would%20have%20a%20new%20name%2C%20but%20not%20necessarily%20a%20new%20object%3A) explains it a bit.

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [January 6, 2023, 5:05pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/3 "2023-01-06T17:05:59Z")

</div>

Thanks for the prompt reply. Although unexpected, but I can understand the referenced effect and hence the last print result. Although, what I still can't comprehend is the second print, right after assigning 222 to arr1.var0, it still prints 111

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 6, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/4 "2023-01-06T17:49:02Z")

</div>

Ah, I see what you're saying.  
I'm just placing this here for reference as we look into this...

```auto
	self.parent.custom.array[1].var0 = 111
	array1 = self.parent.custom.array
	system.perspective.print(self.parent.custom.array[1].var0)
	array1[1].var0 = 222
	system.perspective.print(array1[1].var0)
	system.perspective.print(self.parent.custom.array[1].var0)

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 6, 2023, 6:07pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/5 "2023-01-06T18:07:01Z")

</div>

Interesting. If I log the `id` for the two arrays it turns out we are actually doing a copy on the back-end in order to make this more like Java.

```auto
	self.parent.custom.array[1].var0 = 111
	array1 = self.parent.custom.array
	system.perspective.print(id(self.parent.custom.array)) 
	system.perspective.print(id(array1))
	system.perspective.print(self.parent.custom.array[1].var0)
	array1[1].var0 = 222
	system.perspective.print(array1[1].var0)
	system.perspective.print(self.parent.custom.array[1].var0)

```

Note: the 8 and 9 values are just because I ran this a few times before copying the logging.

```auto
09:58:54.623 [Browser Thread: 58950] INFO Perspective.Designer.Workspace - 8
09:58:54.623 [Browser Thread: 58950] INFO Perspective.Designer.Workspace - 9
09:58:54.624 [Browser Thread: 58950] INFO Perspective.Designer.Workspace - 111
09:58:54.624 [Browser Thread: 58950] INFO Perspective.Designer.Workspace - 111
09:58:54.625 [Browser Thread: 58950] INFO Perspective.Designer.Workspace - 222

```

If we are indeed making a copy, then neither of the last two lines makes sense. I'll reach out to a Developer to get some better insight into what might be happening here.

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [January 6, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/perspective-array-custom-properties/68306/6 "2023-01-06T21:02:17Z")

</div>

Thanks again for the attention and reply.
