You’ve raised some interesting questions!
Let me start by describing how SenseTalk treats these scripts from the point of view of using them as objects with properties. When the egghelper object is first referred to or used in any way, SenseTalk loads the egghelper.script file, and the egghelper object comes into existence. At this time (and only at this time) the properties declared in the script (in “properties … end properties” declarations) are evaluated and become the initial properties of that object. The initialize handler is not called at this time (I’ll explain later).
Similarly, when utility is first used or referred to, the utility.script is read by SenseTalk, and utility’s initial property values are set. In this case, the utility object gets its helpers property set, so egghelper is now a helper of utility (if egghelper had not been used previously, it would get loaded at this point, as described above).
Now, let’s try running something and see what happens. For those of you “following along at home”, you may want to try this by entering the egghelper and utility scripts in a new suite, along with a third script to call them like this:
Start this script in the debugger by holding down the Option key when you run it. Then you can step through the action a line at a time to get a feel for what’s happening here.
When you step into the “run utility.bar” command you should find yourself at the beginning of utility’s bar handler. To arrive at this point, SenseTalk had to load the utility object, which in turn loaded the egghelper object. No handlers have been run yet in either object, and both objects have only the initial property values that were declared in their respective script files.
If you step into the call to “foo()” you’ll find that Eggplant is now executing egghelper’s foo handler. The “foo” message was sent to the utility object, but since it doesn’t have a foo handler, its helper (egghelper) was called on to help out and its foo handler was run on behalf of utility.
We’ve now arrived at the critical point for understanding SenseTalk objects and helpers. The one command in this handler reads “put (my remoteHelper)”. If you execute this command, you’ll see that it displays… nothing!
Now egghelper has a remoteHelper property which was evaluated and assigned a value as soon as the egghelper object’s script file was read. But egghelper’s foo handler is being run on behalf of the utility object, in egghelper’s role as utility’s helper. In this situation, the words “my” and “me” refer to the object being helped, so “my remoteHelper” refers to the remoteHelper property of the utility object. Since it doesn’t have that property, its value is empty.
SenseTalk provides a way to access properties of the helper object itself, by using “this object” instead of “me”. So (if you’re still in the foo handler in the debugger) you can type “put this object’s remoteHelper” in the Do box to see egghelper’s remoteHelper.
I didn’t directly answer your question, but hopefully this explanation has helped you to figure out what you want to do in your situation. The key things to remember are:
- Each SenseTalk object has its own properties.
- Helpers provide an object with additional behavior (handlers) but not properties.
- When a handler is being used as a helper, “me” and “my” refer to the object that is being helped. Use “this object” if you need to refer to the helper object itself.
Oh, I also said I would explain why egghelper’s initialize handler wasn’t called. An initialize message is sent when a “new” expression is used to create an object. For example:
put a new egghelper into newegg
If you run this command, a new object is created with egghelper as its helper. An initialize message is then sent automatically to the new object (newegg). Since newegg doesn’t have an initialize handler (it doesn’t have any handlers of its own in this example), the initialize message is handled by its helper, egghelper.
Hopefully you can see now exactly what this line in the initialize handler will do:
add properties of this object to me
Since egghandler’s initialize handler is being called as a helper of newegg, this command adds all of the properties of egghandler (“this object”) to newegg (“me”).