LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
I am trying to clone a card I use as a template to a new card with a new name.
And I also need to delete a card of which I know the name
I use the code:
clone card "Template"
And this works but the name of the clone is identical to the original (duhh ).
After cloning I do not know which card to change the name of?
Is there a way to give the new card name with the clone or other command?
Go to the dictionary, and look up the keyword "last". This is so useful, but may not help here at all.
So why mention it? Only because it is very convenient when doing what you intended with controls on a card, since any newly created control is automatically the "last" on. (Do watch out when using this keyword for groups. It is not stable). But this may not work with cards, since you can create (or clone) a new card in the middle of other cards in a stack, and that reference is likely broken.
However, if you set the name of the templateCard to something unique, or to something that follows a sequence you have already pre-arranged, you can then identify it and find it. You will already have set its name, and you can even find it within any other cards in the stack, and do what you will...
As regards deleting a named card, why not just delete the card? (Back to the dictionary?)
Dixie wrote:Clone the card and then set the name of 'the last card of this stack' to whatever you want to call it...
I already tried this and it does change a card name but unfortunately it does not change the correct card but another card already existing .
I used the statement: 'set the name of the last card of this stack to thenewcardname' which is the same as you suggested.
Yes, 'last' is very useful... and it does help here !
Changing the name of the card directly after issuing the clone command works here... I've just tried it cloning the last card of a stack and cloning one in the middle of a stack of cards...
Richard... I am not seeing that. If the card is cloned and then renamed directly on the next line, I am seeing that it is the last card that has taken the name and it is the clone...
Richard's point, that you can rely on a newly created, cloned or pasted card to be the current card in the defaultStack has merit. Well and good, though it requires that you work on that card in that place; changing its name, say.
Just don't rely on "last" when dealing with copies of cards.
Richard... I am not seeing that. If the card is cloned and then renamed directly on the next line, I am seeing that it is the last card that has taken the name and it is the clone...
Make a stack with several cards. Find a way to show their numbers. Go to a middle card. Put a button on it, and this in the button script:[codeon mouseUp
clone this cd
set the name of last card to "mmm"
end mouseUp.[/code]
Now check out the name of the card you are on (the cloned card) and see if its name is "mmm"
Rereading Richard and myself, I wonder if there isn't a misunderstanding. It seems that everyone knows that the cloned card is the current card, and that the last card is the last card, and that the two may be, but usually will not be, the same card.
So, use the templateCard, or work directly and immediately on the current card, but do not use the last card. Right?
One can also check IT!
From the dictionary about "clone":
... IT: The clone command places the long id property of the newly created object in the it variable.
...