Page 1 of 1

Converting 2d Array to 1d Array

Posted: Tue Sep 11, 2012 2:31 pm
by Surbhit29
I have a two dimensional array, is their anyway that we can convert this two dimensional array into one dimensional array in LiveCode.

Re: Converting 2d Array to 1d Array

Posted: Tue Sep 11, 2012 3:50 pm
by FourthWorld
There are potentially many ways to do that, but it may take some care to not lose data.

What does the structure of the current array look like, and how do you plan to account for the third dimension of data in the new two-dimensional form?

Re: Converting 2d Array to 1d Array

Posted: Tue Sep 11, 2012 5:21 pm
by dunbarx
I am intrigued as well. As Richard implies, there would have to be a disconnect between some relationships among the data in your 2D array if you transformed it into a simple array. It isn't so much a loss of data as a breaking of connections.

Craig Newman

Re: Converting 2d Array to 1d Array

Posted: Wed Sep 12, 2012 6:45 am
by Surbhit29
Its an array with only integers containing three columns and 9 rows.
But the data gets updated whenever a button is clicked. I want this to be in one single row and data is keep on updating as it is in 2d array.

Re: Converting 2d Array to 1d Array

Posted: Wed Sep 12, 2012 2:54 pm
by FourthWorld
Surbhit29 wrote:Its an array with only integers containing three columns and 9 rows.
But the data gets updated whenever a button is clicked. I want this to be in one single row and data is keep on updating as it is in 2d array.
Data can be updated regardless of the depth of the array. It would be help to understand the goal of reducing the depth.

As for structure, it might look like this:

Code: Select all

[1]
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
   col1,col2,col3
[2]
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
  col1,col2,col3
...
Updating a specific row in that data would require more code and run slower than updating elements in a deeper array, e.g.:

Code: Select all

put tMyArray[1] into tData
put tNewDatum into item 2 of line 4 of tData
put tData into tMyArray[1]
...vs:

Code: Select all

put tNewDatum into tMyArray[1][4][2]
There may still be a benefit to making this transition, however. It's just not clear what the goal is. If you can provide a brief description of that goal we may be able to provide an optimal solution.