Page 1 of 1

Duplicate an array - Solved

Posted: Thu Dec 22, 2022 10:33 pm
by DR White
What is simplest way to duplicate an array?

Array example is MyArray[x,y,z]. I need to copy it to CopyMyArray[x,y,z].

I tried the following:

Code 1:
put MyArray into CopyMyArray

Code 2:
repeat with tXCord = 1 to 12 -- X cordinate
repeat with tYCord = 1 to 12 --Y cordinate
repeat with tZCord = 1 to 12 --Z cordinate
repeat with tItem = 1 to 12 -- item
put item tItem of RungElement[tXCord,tYCord,tZCord] into item tItem of CopyRungElement[ tXCord,tYCord,tZCord]
end repeat
end repeat
end repeat
end repeat

Is there a better way?

Thanks,

David

Re: Duplicate an array

Posted: Thu Dec 22, 2022 11:09 pm
by dunbarx
David.

Not sure what you mean. An array variable is just a variable. As I think you already did, you can:

Code: Select all

put array1 into array2
without issue. What are you running up against, assuming it is not the actual building of the array itself?

Craig

Re: Duplicate an array

Posted: Thu Dec 22, 2022 11:18 pm
by DR White
Thanks

I will use that code.

I most likely have something in my code that is causing an issue.

David

Re: Duplicate an array

Posted: Fri Dec 23, 2022 12:13 am
by DR White
I had a typo in my code.

Sorry for taking your time.

Have a Merry Christmas and Keep Christ in Christmas,

David

Re: Duplicate an array

Posted: Fri Dec 23, 2022 1:48 am
by dunbarx
Good that you can move forward.

Just for me, though, what went wrong with:

Code: Select all

put MyArray into CopyMyArray
Craig

Re: Duplicate an array

Posted: Fri Dec 23, 2022 10:23 am
by DR White
I had been using the code "put MyArray into CopyMyArray" for many days and it was working fine.
I have a function that displays the contents of MyArray and function that displays the contents of CopyMyArray and they
were showing the same contents for many days. Yesterday, I was cleaning up the program code and the two functions no longer
were displaying the same contents. I looked at the two functions and could not see any differences. I wrote some test code, but still was displaying different data between the two arrays. I Thought I copied the "Display MyArray" function and replaced the "Display CopyMyArray" function with "Display MyArray" function (with just the array name changed to CopyMyArray), but it still displayed different contents. I banged my head for a couple of hours and knew nothing else to do except take the issue to the LiveCode Forum. So, once you told me the code I had been using to duplicate an array (put MyArray into CopyMyArray) was good, I copied the "Display MyArray" function and replaced the "Display CopyMyArray" function with "Display MyArray" function (with just the array name changed to CopyMyArray) AGAIN and the contents displayed by both functions were the same.

The LiveCode Forum has been such an AWESOME resource for the almost 10 years that I have been using it. Whenever I reach a coding im-passe, there has always been help available. I strongly recommend LiveCode for anyone who want to learn coding that can build great programs in the shortest possible time and still powerful enough to customize it to do anything you want.

Craig, Thanks again and I admire your interest in asking this followup question,

David :)

Re: Duplicate an array - Solved

Posted: Fri Dec 23, 2022 2:55 pm
by dunbarx
David.

AHA.

Many times I have solved a problem that seemingly ought NOT to be a problem by rewriting from scratch a (sometimes very small) fragment of code. I can only assume that some typo I could not see was fixed.

Happened just the other day. :wink:

Craig