sritcp wrote:Now, for the learning part, why did I need to pass the long id of an object as opposed to the object itself (or its long name) for this to work? The user guide is no help here.
Actually, searching the User Guide for "referring" takes me to section 7.1, "Referring to Objects", which describes using the object's name, ID, or ordinal number to access them.
You can use any of those, including the long name if you like. But since IDs are known to be unique to a stack and it's possible to give the same name to two different objects, I tend to use the long ID rather than the long name.
As for why we can use simply "button 1", I'm not sure I can explain that as well as others here, but I'll try:
Everything in the language boils down to commands and expressions. The command is usually the first word of a statement, followed by expressions which are evaluated to determine what the command should act on and how.
Most objects in LiveCode are also containers. For example, fields and buttons return the textual contents of the control, and even images return their imageData. So when we pass an object directly, that expression evaluates to the object's contents. This makes it easy to do things like
Code: Select all
put field 1 + field 2 into field 3
To distinguish that it's the object itself rather than its contents, we pass an explicit reference to the object, using its ID, name, or ordinal number, e.g.:
MyCommand the long name of btn 1
MyCommand the short ID of img "MyImage"
MyCommand the name of the selectedObject
The ID and name properties can be used in either long or short form, and when using "the name of ..." without either specifier it'll include the object's type, e.g. "button 1".
It can be helpful to take a little time to play around with each form, since each one is slightly different and each is useful in different circumstances.
But for a general absolute reference to an object, "the long id of ..." is usually the best bet.