Duplicate objects at runtime?

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
DevBoyLars
Posts: 216
Joined: Wed Feb 27, 2013 9:04 pm

Duplicate objects at runtime?

Post by DevBoyLars » Sun Mar 31, 2013 3:34 pm

Hi there,
how can I duplicate an object at runtime with all parameters?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Duplicate objects at runtime?

Post by Dixie » Sun Mar 31, 2013 4:17 pm

Enter 'template' into the dictionary... you will see that you can set the properties for a button, field, card etc before you create one of these... also have a look at 'clone' as this too might help you here...

Dixie

DevBoyLars
Posts: 216
Joined: Wed Feb 27, 2013 9:04 pm

Re: Duplicate objects at runtime?

Post by DevBoyLars » Sun Mar 31, 2013 4:42 pm

Ok, thank you.

I think 'clone' is what I need.

If I clone an object, how can I distinguish them?

In other programming languages I would create the duplicate with help of a new instance-variable. Such as x = y. So x would be a duplicate of object y.

If I write 'clone y' there's a clone of y, but how can I handle it?

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Duplicate objects at runtime?

Post by dave_probertGA6e24 » Sun Mar 31, 2013 6:14 pm

Hi,

By using 'it' - the variable called 'it' will contain the long ID of the new cloned object.
for example:

Code: Select all

clone button "foo"
set the name of it to "bar"
set the loc of button "bar" to 100,100
The 'it' variable is used all over the place in LC, but it's only mentioned in the docs using one line in most cases - easy to overlook.

Hope that helps,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

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

Re: Duplicate objects at runtime?

Post by dunbarx » Mon Apr 01, 2013 3:04 am

Hi.

Know also that the "last" keyword might be helpful here, if you intend to grab that last created object and work with it. Be careful, though, as the "last" keyword is not stable when cloning groups, though it works with all other object types. The dictionary has a user note, ahem, by me...
....The "last" keyword is not stable when referring to groups. So if one creates several groups, referencing the "last" group may not return the group actual ly created last. Using the "templateGroup" is a workaround, since when creating a new group one can, for example, set the name of the templateGroup to something unique, and be able to find the last group by name. Also, trapping the "newGroup" message with an appropriate script can be used to find the last group....
This is not an issue with other objects,

Craig Newman

Post Reply