# Bidimensional array indexing

Hey there!

Just a simple question. I am trying to access and modify an element in a bidimensional array/list, but it is not working as I expected and I am missing something. I cannot find anything similar in the manual or forum.

This example is just for testing with onClick action in a normal button:

``````
X = [["A","B"],["C","D"]]
system.tag.write("[default]NewTag",X)

self.getSibling("Label_0").props.text = X[0]
#ok, I see ["A","B"]

self.getSibling("Label_0").props.text = X[0][0]
#ok, I see A

self.getSibling("Label_0").props.text = Y[0]
#I see ['A','B']

self.getSibling("Label_0").props.text = Y[0][0]
#I get literally: [
``````

Could anyone explain the difference?

And then, how would I modify any element in the bidimensional list? Would it be different if work with the X array or Y array? Example (when pressing another button):

``````
X[0] = ["A","B","F"]
Y[0] = ["A","B","F"]

X[0][0] = "Hello"
Y[0][0] = "World"
``````

Ignitionâ€™s tags donâ€™t support anything beyond 1d arrays. When you write the 2d array into it and then read it back I think youâ€™re getting a string representation of some object in memory instead of a value you can work with.

Thanks for the quick respone @Kevin.Herron ,

And do you have a tip about how to solve this?

I would like to work with 2d arrays because:

1. dataset cells do not support arrays
2. all the cells inside a column of a dataset must be the same type

Maybe work with UDTs?

Thanks,

Isnâ€™t a dataset basically a 2d array?

A dataset cell containing an array would be a 3rd dimension.

Yes, I would need that 3rd dimension.

Depending on the column and the row, the cell must contain a different array inside.

My list would be then something like this (2x2 matrix where the cells are arrays):

X = [[array1,array2],[array3,array4]]

I also need to keep those values in memory, and that is why I thought about writing into tags.

If you donâ€™t need to access the data from multiple scopes (Vision Client vs Gateway) you can maybe just store it in a global variable or the globals map.

Also worth considering storing some amount of the content in a json structure. You could use a â€śdocumentâ€ť tag and have access to the content through the tag editing GUI. That document holding everything could easily be pushed anywhere/everywhere as an encoded json string.

1 Like

@Kevin.Herron I need to access the data from perspective. I am developing a SCADA project only using perspective. Not sure if I accessing from a perspective client would create any problem.

@rcrownover I am a little newby to Ignition. Could you give a simple example of your idea?

[UPDATE]

I just tried this example and I am still stuck:

On a first button:

``````X = [["A","B"],["C","D"]]
jsonString = system.util.jsonEncode(X)
system.tag.write("[default]NewTag",jsonString)
#NewTag type is document, and I can see that the array is written (attached image)``````

On a second button:

``````jsonString = system.tag.readBlocking("[default]NewTag")[0].value

#all of this looks ok:
self.getSibling("Label").props.text = jsonString
# [["A","B"],["C","D"]]
self.getSibling("Label").props.text = jsonString[0]
#["A","B"]
self.getSibling("Label").props.text = jsonString[0][0]
#A

#but I cannot modify like this:
jsonString[0][0] = "Z" # or even jsonString[0][0] = another array
``````

I tried using system.util.jsonDecode but not working or not sure how to use it.

Thanks guys,

This has no sense, is an array after all.

I feel you are not in a good path but Iâ€™ll help you to at least write back to the tag with new value.

``````X = [["A","B"],["C","D"]]
jsonString = system.util.jsonEncode(X)
system.tag.write("[default]NewTag",jsonString)