Question regarding helpers and properties...


I'm having a rough time figuring out a way to use a script's properties as a prototype object.

This is what I'm attempting to do:

// prototype.script


something: someValue

end properties

// scriptThatShouldInheritProperties.script

set me to be a new prototype with (something: myValue) // What should go here instead?? This line doesn't work, but I believe it illustrates what I'm trying to do.


EDIT: The line *does* work if I replace "me" with "foo" or any string which can be the name of a variable, but the goal is to not create another object when the scriptThatShouldInheritProperties already is one itself.


  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    The idea of a prototype object is to be a template from which you can make new objects that inherit the behavior (and some initial property values) of the prototype. So go ahead and make a new object -- it won't cost you anything. :wink:

    If you really only need a single object, then you can just use the script as the object. Its handlers can access its properties using the word "my", like "my something" in your example. The best example to get an idea about working with objects in SenseTalk is probably still the banking tutorial:

    I suggest reading through that and if you have any other specific questions, please feel free to post them here.
  • ag47ag47 Member
    Hi Doug,

    Thanks for the example! It's possible I may have missed something, but I'm not sure if it answers my question(s).

    In the second script in my example, I have the first (prototype) script identified as a helper in the properties of the second script. However, on the next line I have "log my something" and nothing gets logged in the run window when I run the second script even though "something" is explicitly set to "someValue" in the prototype script's properties. My two questions are:

    A) Why is the second script not inheriting the properties?
    B) Is there a way to make the second script itself (without creating a new object inside it) inherit from the prototype? As the second script is already an object, I suppose just seems redundant to make a new object.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    When you use the "new" operator to create an object from a prototype, it sets the prototype as a helper of the new object AND copies the prototype's properties into the new object. But if you directly set one object to be a helper of another (as you've done in your second script) you'll inherit the behavior of the first (helper) script, but not its properties.

    A) Why is the second script not inheriting the properties?

    There is no inheritance of properties in SenseTalk -- each object has its own properties. You can copy properties from one object to another using the "add properties" or "replace properties" commands, or implicitly by using the "new" operator to create an object from a prototype.

    B) Is there a way to make the second script itself (without creating a new object inside it) inherit from the prototype?

    Properties are not inherited from a helper, only behaviors. But the helper (the prototype) can include a handler (behavior) that provides a value. So, in your first script you could include this handler:
    to handle something
        return property something of this object
    end something
    Then you would be able to use "my something" in the second script to access the value returned by the something handler (which in this case would be the value of the first script's something property).

    Note: It's important to use "property something of this object" in the helper's script, not "my something" because a helper takes on the identity of the object it's helping (meaning that "me" and "my" refer to the helped object in that situation).
Sign In or Register to comment.