Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
mrcoollion
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Post
by mrcoollion » Fri May 27, 2016 3:29 pm
I want to clone a card (in background) without actually going to that card.
The statement below works fine but after this part of the script the new card is shown and I need to stay on the card within the script the clone is initiated from (a button).
Code: Select all
clone card "Card template"
set the name of card "Card template" of this stack to thenewcardname // Because it is a clone it does not matter which card is renamed.
Workin in Livecode 8.0
Regards,
Paul
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10354
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri May 27, 2016 4:13 pm
Hi.
Read about locking the screen in the dictionary. Now think about setting up a way to identify your source card, perhaps by marking or naming, and throwing in a line that returns to that card after the clone has been created. A shortcut might be that you exploit the fact that the cloned card will immediately follow the source card, but that is lazy.
Craig Newman.
-
mrcoollion
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Post
by mrcoollion » Fri May 27, 2016 4:34 pm
I will try some stuff , I think that lock screen and go back to original card will initiale the 'on opencard' routine which I do not want.
I will let you know.
Thanks Craig.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10354
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri May 27, 2016 4:39 pm
Well then lock messages as well.
This is a great tool to bypass stuff that you may want in some processes, but not in certain others.
Craig.
-
Klaus
- Posts: 14208
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri May 27, 2016 4:40 pm
Hi mrcoollion,
"lock messages" is the magic word!
Code: Select all
...
lock screen
clone cd X
lock messages
go cd "the previous one"
unlock messages
unlock screen
...
Best
Klaus
-
mrcoollion
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Post
by mrcoollion » Fri May 27, 2016 4:44 pm
Tried the lock screen and although it looks ok the on opencard routine is activated ;-( (which I expected to be).
Is there any other copy command i can use to copy a card and rename it?
gtestvar1 is a global variable available in open card
Code: Select all
on opencard
put "Past Opencard ;-(" into gtestvar1
end opencard
The code in a button in card "AddMenuItems"
Code: Select all
lock screen
put empty into gtestvar1
clone card "Card template" // Works but which card to change the name of?
set the name of card "Card template" of this stack to thenewcardname // Picks the first found but that does not matter. is is a clone anyway :-)
go card "AddMenuItems"
unlock screen
answer gtestvar1 // for test
regards,
Paul
-
Klaus
- Posts: 14208
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri May 27, 2016 5:27 pm
Hi Paul,
you already gave the answer!
Code: Select all
...
lock screen
put empty into gtestvar1
clone card "Card template"
## Works but which card to change the name of?
## You already found out that you ARE on the new card at this point! :-)
## So lets use this fact and:
set the name of THIS cd to thenewcardname // Picks the first found but that does not matter. is is a clone anyway :-)
go card "AddMenuItems"
unlock screen
answer gtestvar1
...
Best
Klaus
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10354
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri May 27, 2016 11:18 pm
Hi.
Both Klaus and I mentiined that you can lock messages (though I beat him by one minute. Hah!)
But you did see that (them) right?
Craig
-
mrcoollion
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Post
by mrcoollion » Sat May 28, 2016 9:33 am
Thanks for all the advise friends.
The script below works fine and I will use it.
Code: Select all
lock screen
clone card "Card template"
set the name of card "Card template" of this stack to thenewcardname // Picks the first found but that does not matter, it is a clone anyway :-)
lock messages
go card "AddMenuItems" // This script is in a button on this card
unlock messages
unlock screen
I did not use the 'set the name of THIS cd to thenewcardname ' because after doing so I almost lost 2 weeks of work when it renamed the card my code was on and I almost removed it. I do auto sync my scripts to another safe place with BitTorrentSync but that is not a backup (in my opinion best free synctool available)! It made me aware of this and now I use 'cobian backup' to make a copy every minute of changed scripts (works great). It has an option to remove empty folders in the advanced section of a task so it actually only backups changed scripts (no performance problems at all,
http://www.cobiansoft.com).
Thanks for everything.
Regards,
Paul