ID's are settable???

Richard Gaskin ambassador at fourthworld.com
Thu Jan 13 11:21:37 EST 2011


DunbarX wrote:

> Is it so? You can now set the id of any object, like a button?

Yep.

> I tried it, and you can. Did I miss this somewhere?

I believe it's in the Engine Change log, but comes with a caveat that it 
was added specifically to facilitate translating stacks to and from a 
textual format and any other use is unsupported and at your own risk.

Given the power to completely muck up your work with ID conflicts, the 
caveat is understandable.

> I think this is a terrible new feature, If I am not missing something. What
> is the point of the altID now, which used to be very cool?

The altID property was first implemented for importing SuperCard 
projects, for the benefit of those scripts that refer to objects by 
their ID.

Back then Dr. Raney took a dim view of user-settable IDs, recognizing it 
as handing the scripter a gun and a map to one's foot. ;)

That said, for the careful developer the ability to set IDs is a 
wonderful thing, and for the most part now obviates any need for altID.



Side note: among the other caveats wisely applied with setting IDs, 
you'll want to be aware of the ID limit currently in LiveCode, which is 
a little over 2 billion.

IDs begin by default at 1002 for the card, with any new object getting 
1003 and so on. The stack ID has the unique role of being used only as 
the storage for the highest ID currently in use; you can expect it to 
change as you add new objects.

Since IDs begin with 1002 it seems unlikely that anyone will ever exceed 
the 2 billion limit, but consider the DataGrid and other such things 
that may create and dispose of hundreds of objects at a time.  Such 
things may over the course of several years raise the ID incrementer 
beyond 2 billion, sooner if you set the ID to a very high number manually.

In testing out what happens when the ID limit is reached, I found a 
curious thing:  you can continue to create new objects, but once their 
IDs pass the limit they will no longer respond to the pointer tool, and 
may eventually make a stack unopenable.

The good news is that the workaround is relatively simple:   if you see 
a stack moving its IDs toward the limit, you can make a new stack and 
copy the objects from the old one to the new one, effectively resetting 
their IDs to start at 1002 again.

It might be nice to have the ID limit raised, or to find some method to 
roll over and reuse unused IDs, but I recognize these options would be 
costly to implement and indeed it's a rare case where one would need to 
be concerned about it anyway.

But that said, I have one project which uses two data grids and a custom 
control comprised of a few hundred objects which is rebuilt dynamically 
with certain user actions.  In that project the IDs are currently over 2 
million.  The good news is that the stack is never saved when running in 
the standalone (the data is stored separately from the UI), so the IDs 
only increment in development.  Still, I can expect that during the life 
cycle of the project we will need to do the copy-and-paste to reset the IDs.

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv




More information about the use-livecode mailing list