Copy and rename a button - which takes precedence?

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

M-A Kuttner
Posts: 50
Joined: Mon Apr 03, 2017 3:55 pm

Copy and rename a button - which takes precedence?

Post by M-A Kuttner » Wed Nov 02, 2022 10:11 pm

Hi all. I've got a button that I want to copy via a script and then rename the copy to a new button name. The script is essentially this:

Code: Select all

copy button ButtonName
paste
set the name of button ButtonName to "ButtonName1"
My question is; after I've copied and pasted the button, how does LC decide which of the buttons I will be renaming. Does it prioritize by earliest ID, latest ID, highest layer number, or something else? When I rename button ButtonName, am I renaming the original or the copy?

Thanks!
M-A
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 128
Joined: Tue Apr 11, 2006 7:02 pm
Contact:

Re: Copy and rename a button - which takes precedence?

Post by mtalluto » Wed Nov 02, 2022 11:22 pm

Hi M-A

You can use 'it' to identify the reference to the pasted control.

Here is some example code:

Code: Select all

on mouseUp
     copy button "marko"
     paste
     set the name of it to "polo"
end mouseUp
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Copy and rename a button - which takes precedence?

Post by jmburnod » Wed Nov 02, 2022 11:28 pm

Hi,

You may use clone command.
Something like that.

Code: Select all

on cloneOneBtn pTargetName, pNewName
   clone btn pTargetName
   set the name of last btn to pNewName
end cloneOneBtn
Best regards
Jean-Marc
https://alternatic.ch

M-A Kuttner
Posts: 50
Joined: Mon Apr 03, 2017 3:55 pm

Re: Copy and rename a button - which takes precedence?

Post by M-A Kuttner » Thu Nov 03, 2022 2:14 am

Many thanks, Mark and Jean-Marc!
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.

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

Re: Copy and rename a button - which takes precedence?

Post by dunbarx » Thu Nov 03, 2022 2:30 am

M-A.

Know that whenever you create any new control, however you do that, it can be accessed via the "last" keyword, before you know anything else about it. But just as the local variable "it" can change almost at once, depending on what is going on in a handler, it is a good idea to explicitly set certain important properties, like the name, of that last control.

Know also "last" does not seem to work with groups.

Craig

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

Re: Copy and rename a button - which takes precedence?

Post by Klaus » Thu Nov 03, 2022 9:26 am

Hi friends,

we can do this:

Code: Select all

on cloneOneBtn pTargetName, pNewName
   clone btn pTargetName AS pNewName
end cloneOneBtn
Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Copy and rename a button - which takes precedence?

Post by jmburnod » Thu Nov 03, 2022 12:50 pm

Saperlipopette !!
Klaus made it shorter 8)
https://alternatic.ch

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

Re: Copy and rename a button - which takes precedence?

Post by Klaus » Thu Nov 03, 2022 12:56 pm

That's pure lazyness! :-D

M-A Kuttner
Posts: 50
Joined: Mon Apr 03, 2017 3:55 pm

Re: Copy and rename a button - which takes precedence?

Post by M-A Kuttner » Thu Nov 03, 2022 1:22 pm

Wow, great! Many thanks guys!
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.

stam
Posts: 3070
Joined: Sun Jun 04, 2006 9:39 pm

Re: Copy and rename a button - which takes precedence?

Post by stam » Thu Nov 03, 2022 4:07 pm

Klaus wrote:
Thu Nov 03, 2022 12:56 pm
That's pure lazyness! :-D
That's to be applauded ;)

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

Re: Copy and rename a button - which takes precedence?

Post by dunbarx » Thu Nov 03, 2022 5:21 pm

Spelling "laziness" with a "Y" is not lazy, it is extra work for little gain.

Craig

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

Re: Copy and rename a button - which takes precedence?

Post by Klaus » Thu Nov 03, 2022 5:25 pm

I'm a 10 finger typer, so that does not matter to me... 8)

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

Re: Copy and rename a button - which takes precedence?

Post by Klaus » Thu Nov 03, 2022 7:24 pm

Or was that a joke that (again) I didn't get?

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

Re: Copy and rename a button - which takes precedence?

Post by dunbarx » Fri Nov 04, 2022 6:09 am

Klaus.

The extra work I mentioned derives from the longer distance one has to move one's finger in order to access the "Y" as opposed to the "I".

This is wasted energy; it requires the body to burn more calories since it takes extra work to move ones fingers that extra distance. It takes energy to displace considerable additional air, and I will not even go into the extra time required for that additional finger travel, including the return travel time, which in turn requires the computer itself to be powered on longer than necessary.

No wonder the glaciers are disappearing.

Craig

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

Re: Copy and rename a button - which takes precedence?

Post by Klaus » Fri Nov 04, 2022 9:57 am

AHA! :-D

OK, that joke may not work so well with german keyboards, where the Y is at another place,
right above the left CMD and ALT key. ;-)
germankeyboardmac.jpeg

Post Reply