Page 1 of 1
Duplicate objects at runtime?
Posted: Sun Mar 31, 2013 3:34 pm
by DevBoyLars
Hi there,
how can I duplicate an object at runtime with all parameters?
Re: Duplicate objects at runtime?
Posted: Sun Mar 31, 2013 4:17 pm
by Dixie
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
Re: Duplicate objects at runtime?
Posted: Sun Mar 31, 2013 4:42 pm
by DevBoyLars
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?
Re: Duplicate objects at runtime?
Posted: Sun Mar 31, 2013 6:14 pm
by dave_probertGA6e24
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
Re: Duplicate objects at runtime?
Posted: Mon Apr 01, 2013 3:04 am
by dunbarx
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