Moving objects between cards

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Moving objects between cards

Post by glenn9 » Fri Feb 04, 2022 2:10 pm

I'm conscious that I've been fairly quiet on the forum over the last few months but I have been busy livecoding and tinkering with my apps in the background...

The problem that I can't seem to solve at the moment is that I'm wanting to programatically move a group from one card to a different a different card.

Assuming the Group is originally in card"A", I've tried various permutations of:

Code: Select all

put group"testGroup" into card"B" 
but these of course don't work!

Grateful for any hints!

Many thanks,

Regards,

Glenn

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving objects between cards

Post by Klaus » Fri Feb 04, 2022 2:26 pm

Hi Glenn,

almost! :-)
If you are on the card with your group, you can:

Code: Select all

...
place grp "testGroup" ONTO cd "B"
...
If you are on card "B" then this will throw an error -> can't find object
But this will do in that case:

Code: Select all

...
place bg "testGroup" ONTO cd "B"
...
put the num of grps -> will return the number of all groups on the current card
put the num of bgs -> will return the number of all groups in the current stack

So groups are counted relative to the card, backgrounds relative to the stack.

The opposite (remove a group) goes this way:

Code: Select all

...
remove grp "testGroup" from cd "B"
...
Best

Klaus

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Moving objects between cards

Post by glenn9 » Fri Feb 04, 2022 2:45 pm

Many thanks Klaus, that was a great help.

Regards,

Glenn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Moving objects between cards

Post by dunbarx » Fri Feb 04, 2022 2:56 pm

What Klaus said.

You can also use the "copy" command to the same effect:

Code: Select all

copy group "yourGroup" to card "otherCard"
Craig

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving objects between cards

Post by Klaus » Fri Feb 04, 2022 2:58 pm

dunbarx wrote:
Fri Feb 04, 2022 2:56 pm
...
You can also use the "copy" command to the same effect:

Code: Select all

copy group "yourGroup" to card "otherCard"
Not really, Craig! :D

In that case you end with two identical groups in your stack.
PLACEing will place the SAME group onto another card.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Moving objects between cards

Post by dunbarx » Fri Feb 04, 2022 3:10 pm

Klaus.

Certainly. I thought that the OP wanted a copy of the group somewhere else.

@Glenn9. Do you see what Klaus pointed out? If you "place" a group onto another card in the same stack, then that group is an instance of a single group shared among all the cards it resides on. Changing it in one place will change it in all places.

If you "copy" that group, you essentially make a new exact copy, but one that does not share the structure of the original, nor does it "see" any changes to that original. Since you cannot "place" a group onto a different stack, that is how one would proceed if you wanted to make a copy in another stack.

Craig

Post Reply