Converting 2d Array to 1d Array

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Surbhit29
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Converting 2d Array to 1d Array

Post by Surbhit29 » Tue Sep 11, 2012 2:31 pm

I have a two dimensional array, is their anyway that we can convert this two dimensional array into one dimensional array in LiveCode.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Converting 2d Array to 1d Array

Post by FourthWorld » Tue Sep 11, 2012 3:50 pm

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?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6163
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Converting 2d Array to 1d Array

Post by dunbarx » Tue Sep 11, 2012 5:21 pm

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

Surbhit29
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: Converting 2d Array to 1d Array

Post by Surbhit29 » Wed Sep 12, 2012 6:45 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Converting 2d Array to 1d Array

Post by FourthWorld » Wed Sep 12, 2012 2:54 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”