[Squeakland] Fwd: misc: elementNumber, obj id

Scott Wallace scott.wallace at squeakland.org
Wed Sep 28 18:33:17 PDT 2005


Hi, Randy.

Yes, the elementNumber of an object in a container will change as the 
order of objects in the container changes, and the order depends on 
the order in which the objects were added to the container... and 
when you "pick up" an object and then drop it back into a container, 
that counts as being freshly added to the container, so the last 
object "touched" will be the one with the largest elementNumber.  So, 
in short, you can't count on elementNumber to stay the same unless 
you're not "touching" the objects.

So what to do instead?  I'd recommend that you maintain your *own* 
"idNumber" variable in the objects in question, and give each of the 
objects its own unique  value for an idNumber... and use *those* in 
your reckonings instead of "elementNumber."  Since this is a variable 
that you have created and assigned values to yourself, its value is 
not going to change unless you proactively change it, so you should 
be able to use it to distinguish reliably among siblings.

Cheers,

   -- Scott

PS:  If the above isn't clear, please send a concrete example and we 
can work it through together.


>>From: "Randy Heiland" <heiland at indiana.edu>
>>To: <squeakland at squeakland.org>
>>Date: Wed, 28 Sep 2005 11:16:28 -0500
>>
>>Can someone tell me a bit more about this tile in the miscellaneous
>>category?  Its balloon help says "my index in my container".  I'm simply
>>experimenting with some siblings in a playfield, seeing if I can have
>>sibling-dependent behavior based on each sibling's identifier/elementNumber.
>>It seems that whenever I grab one of the siblings and move it, its
>>elementNumber changes.  I'd like some fixed identifier assoc'd with each
>>sibling.
>>
>>--Randy


More information about the Squeakland mailing list