Stability of a button's ID property when cloning stacks
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Stability of a button's ID property when cloning stacks
Hi,
One of the results when copying or moving controls between stacks is that Livecode usually (always?) assigns them a new ID number. This renumbering can cause issues with behavior buttons and image assignments . However, I have just had it pointed out to me that if the control, e.g. a button, is on a stack that is cloned then it retains it's original ID. I can see the logic as the copy of the stack will have a new name so the object references will be unique.
I wonder if anyone has ever seen a control given a new ID as the result of a clone operation? I'm asking the question because while I trust my source I do not trust my understanding of what he sent me.
One of the results when copying or moving controls between stacks is that Livecode usually (always?) assigns them a new ID number. This renumbering can cause issues with behavior buttons and image assignments . However, I have just had it pointed out to me that if the control, e.g. a button, is on a stack that is cloned then it retains it's original ID. I can see the logic as the copy of the stack will have a new name so the object references will be unique.
I wonder if anyone has ever seen a control given a new ID as the result of a clone operation? I'm asking the question because while I trust my source I do not trust my understanding of what he sent me.
best wishes
Skids
Skids
Re: Stability of a button's ID property when cloning stacks
Simon.
I made two new stacks and put a button on one of them. ID was 1003. I copied the button and pasted onto the other stack. Button there was also ID 1003.
I deleted the button on the second stack, and went back to the first stack. I copied the button again, and pasted as before. Copy was ID 1004.
Repeated the process. The new copies had ID's 1005, 1006, etc.
Deleted both stacks and made two new ones. The above action repeated itself, that is, the FIRST time I copied, the ID's stayed the same.
When I delete only the second stack, and then paste into a new one from the first, the ID of the copy holds at 1003. So the second stack, if it ever had a button, "remembered" that, and reserved that ID.
Craig
I made two new stacks and put a button on one of them. ID was 1003. I copied the button and pasted onto the other stack. Button there was also ID 1003.
I deleted the button on the second stack, and went back to the first stack. I copied the button again, and pasted as before. Copy was ID 1004.
Repeated the process. The new copies had ID's 1005, 1006, etc.
Deleted both stacks and made two new ones. The above action repeated itself, that is, the FIRST time I copied, the ID's stayed the same.
When I delete only the second stack, and then paste into a new one from the first, the ID of the copy holds at 1003. So the second stack, if it ever had a button, "remembered" that, and reserved that ID.
Craig
Re: Stability of a button's ID property when cloning stacks
Hi Simon,
To avoid this, i usealy the name of btn to define behavior of controls with a script on preopenstack.
There is also altID but i never used it but it is maybe useful in your case
Best regards
Jean-Marc
This renumbering can cause issues with behavior buttons
To avoid this, i usealy the name of btn to define behavior of controls with a script on preopenstack.
There is also altID but i never used it but it is maybe useful in your case
Best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 10055
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Stability of a button's ID property when cloning stacks
Cloning stacks and copying controls are very different operations. I haven't seen a cloned stack alter the IDs of the controls within it, but we would expect any copied control to have its ID changed.
It may help to keep in mind how IDs are assigned: the ID property of a stack serves a unique role, different from other object IDs. In all other objects, its ID property is used to uniquely identity the object. Stack objects are identified by name; the ID property of a stack serves only as storage for the next available ID for other objects within it. As an object is created within a stack, the stack's ID is used as the ID of the new object, and the stack's ID property is incremented. This central place for next available ID keeps object creation from having to look through all objects to determine the next available ID.
With that in mind, we can appreciate how cloning an entire stack will preserve IDs, while cloning or copying any other object within a stack may necessitate changing the new object's ID to avoid conflict with existing objects.
It may help to keep in mind how IDs are assigned: the ID property of a stack serves a unique role, different from other object IDs. In all other objects, its ID property is used to uniquely identity the object. Stack objects are identified by name; the ID property of a stack serves only as storage for the next available ID for other objects within it. As an object is created within a stack, the stack's ID is used as the ID of the new object, and the stack's ID property is incremented. This central place for next available ID keeps object creation from having to look through all objects to determine the next available ID.
With that in mind, we can appreciate how cloning an entire stack will preserve IDs, while cloning or copying any other object within a stack may necessitate changing the new object's ID to avoid conflict with existing objects.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Stability of a button's ID property when cloning stacks
Actually, the first control of a new stack is always 1003 so nothing is remembered, just as the first card of a new stack is always 1002.When I delete only the second stack, and then paste into a new one from the first, the ID of the copy holds at 1003. So the second stack, if it ever had a button, "remembered" that, and reserved that ID.
A better test is to copy a control from one stack and paste it into another stack that already has many of its own controls. The pasted control will have the next ID in sequential order.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Stability of a button's ID property when cloning stacks
Jacque.
Simon originally asked:
But I believe that the issue Simon is on about is controls with the same ID in any situation at all, perhaps especially with behaviors. The answer here is "yes" as well, and so one must be careful to remember the fact that any duplicate ID's in a project are in controls that live in different stacks. This is how it has always been.
Craig
EDIT:
For learning, it might be important to know that a stack will not assign a lower ID for a new control even if that ID is "available", that is, a control that has since been deleted was originally assigned that number. This is a good thing.
Simon originally asked:
The answer is "yes", unless that clone is pasted into a brand new stack that, of course, never had any controls. In that case, as you say, the new stack simply applies "1003" to its new child, perhaps the same as the original.I wonder if anyone has ever seen a control given a new ID as the result of a clone operation?
But I believe that the issue Simon is on about is controls with the same ID in any situation at all, perhaps especially with behaviors. The answer here is "yes" as well, and so one must be careful to remember the fact that any duplicate ID's in a project are in controls that live in different stacks. This is how it has always been.
Craig
EDIT:
For learning, it might be important to know that a stack will not assign a lower ID for a new control even if that ID is "available", that is, a control that has since been deleted was originally assigned that number. This is a good thing.
Last edited by dunbarx on Wed Jun 24, 2020 7:45 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 10116
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stability of a button's ID property when cloning stacks
I have just made a very silly stack called "sillyCLONE"
with a single button 'CLONE' and as single field 'fBTN" on a card.
- -
The button contains this script:
Every time one clicks on that button it clones the card with the button and the field: each time the
button and the field are given new IDs.
OBVIOUSLY this is NOT stack cloning, it is card cloning.
with a single button 'CLONE' and as single field 'fBTN" on a card.
- -
The button contains this script:
Code: Select all
on mouseDown
put the id of me into fld "fBTN"
end mouseDown
on mouseUp
clone this card
end mouseUp
button and the field are given new IDs.
OBVIOUSLY this is NOT stack cloning, it is card cloning.
- Attachments
-
- sillyCLONE.livecode.zip
- Here's the stack.
- (1.02 KiB) Downloaded 249 times
Re: Stability of a button's ID property when cloning stacks
Richmond.
People are constantly interchanging, in error, "silicone" for "silicon". Drives me nuts.
I have never seen anyone go so far out as "sillyClone".
Craig
People are constantly interchanging, in error, "silicone" for "silicon". Drives me nuts.
I have never seen anyone go so far out as "sillyClone".
Craig
-
- Livecode Opensource Backer
- Posts: 10116
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stability of a button's ID property when cloning stacks
That was NOT in reference to either silicon or silicone; it didn't even cross my mind; just had to think of
something to call that stack.
-
- Livecode Opensource Backer
- Posts: 10116
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stability of a button's ID property when cloning stacks
The lips are to keep Craig happy.

[Thought that b**bs might be "pushing things too far."]
https://youtu.be/z-znH5v2Pqg
Seems that buttons do retain their ID numbers.
Although, personally, I always stick with the name of an object, even when referring in a way that requires the ID:
Code: Select all
set the backGroundPattern of grc "crud" to the ID of img "fatLips"
- Attachments
-
- sillyCLONE 2.livecode.zip
- Here's the stack.
- (5.89 KiB) Downloaded 240 times
Re: Stability of a button's ID property when cloning stacks
Richmond.That was NOT in reference to either silicon or silicone; it didn't even cross my mind; just had to think of
something to call that stack.
Baby.
I knew that.
Craig
-
- Livecode Opensource Backer
- Posts: 10116
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stability of a button's ID property when cloning stacks
Craigie-waigie, nobody has called me "Baby" for years . . . we could take this further if only . . .Richmond.
Baby.
I knew that.
Craig

-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Stability of a button's ID property when cloning stacks
Ignoring the last few divergent posts thank you all for an interesting debate.
My point of interest in IDs comes from creating a palette stack that stores custom controls for use in the IDE. Typically these are groups that also use a behavior button which may be either part of the group or external to it.
If your great custom control uses both images and behavior buttons then a few hoops have to be jumped through when the components are copied to a project stack as the behavior button and images will have new IDs. So not only does the behavior of the group have to be updated to point at the copy of the behavior button, the code also needs to determine the ID number allocated to the copy of the behavior button.
I have developed one version that conducts searches for the name of the behavior button but I am aware that button names are not unique.
I am looking at designs of the palette stack that use sub-stacks that are cloned instead of copied as a method of preserving the group behavior links when the group controls are added to a project stack.
phew - I hope that makes sense - its been 32 degrees here which is hot for a celt so thats my excuse if I have just typed drivel
My point of interest in IDs comes from creating a palette stack that stores custom controls for use in the IDE. Typically these are groups that also use a behavior button which may be either part of the group or external to it.
If your great custom control uses both images and behavior buttons then a few hoops have to be jumped through when the components are copied to a project stack as the behavior button and images will have new IDs. So not only does the behavior of the group have to be updated to point at the copy of the behavior button, the code also needs to determine the ID number allocated to the copy of the behavior button.
I have developed one version that conducts searches for the name of the behavior button but I am aware that button names are not unique.
I am looking at designs of the palette stack that use sub-stacks that are cloned instead of copied as a method of preserving the group behavior links when the group controls are added to a project stack.
phew - I hope that makes sense - its been 32 degrees here which is hot for a celt so thats my excuse if I have just typed drivel

best wishes
Skids
Skids
-
- Livecode Opensource Backer
- Posts: 10116
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stability of a button's ID property when cloning stacks
Just give your custom controls names,
then you shouldn't have to fuss about ID numbers at all.
then you shouldn't have to fuss about ID numbers at all.
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Stability of a button's ID property when cloning stacks
If only it was that simple, the problem is with behavior buttons and to a lesser extent images. Looking at behaviors lets say that I name my group control smkPickList. This control will probably only be used once in a project so its code is stored in a behavior button inside the control's grouprichmond62 wrote: ↑Thu Jun 25, 2020 7:45 amJust give your custom controls names,
then you shouldn't have to fuss about ID numbers at all.
Lets say that when the master copy is on the palette tools stack, named stack "ToolsPalette" its behavior is stored inside the group and has a name of "smkPickListBehavior" and an ID of 1023.
The palette stack allows dragging and dropping of group "smkPickList", but its just a copy and paste action. When a copy is made say to stack "Project" the control group is allocated a new ID and so are all the controls inside the group. Inspecting the copy of the group in stack "Project" will show that its behavior pointer is still set to button ID 1023 of stack "ToolsPalette" and worse the ID of the button "smkPickListBehavior" inside the copy of the group will now have a new ID number because it is now on a new stack.
At the moment my code reads the ID of the original behavior of the group, determines the name of the behavior then searches for the name of the behavior button in the project stack and then resets the group to use the local behavior. It all works as long as the button names are unique.
It also works with behavior buttons stored outside the group in a similar way.
Images : if the group control assigns images to buttons then there are problems as the image will most likely be allocated new IDs breaking the allocations made in your original control group. This means that code similar to this has to be employed :
Code: Select all
set the icon of button "SortA" of me to the short id of image "imgSort" of me
So its all a bit of a fuss.....
best wishes
Skids
Skids