User Guide
Chapter 3116
• The following statements use the parent script and ancestor script.
This statement creates an instance of the parent script:
set m = new(script "man")
This statement makes the man walk:
call #walk, m
-- "Animal walking with 2 legs"
This statement makes the man run:
set msg = #run
call msg, m
-- "Man running with 2 legs and rock"
This statement creates a second instance of the parent script:
set m2 = new(script "man")
This statement sends a message to both instances of the parent script:
call msg, [m, m2]
-- "Man running with 2 legs "
-- "Man running with 2 legs "
callAncestor
Syntax
callAncestor handlerName, script, {args...}
Description
Command; sends a message to a child object’s ancestor script, where handlerName is the name of
the handler to be activated,
script references the script instance or a list of script instances, and
args are any optional parameters to be passed to the handler.
If
script is a single script instance, an error alert occurs if the handler is not defined in the
ancestor of the script.
If
script is a list of script instances, the message is sent to each item in the list in turn. In this
case, if the handler is not defined in an ancestor script, no alert is generated.
Ancestors can, in turn, have their own ancestors.
When you use
callAncestor, the name of the handler can be a variable, and you can explicitly
bypass the handlers in the primary script and go directly to the ancestor script.
Example
This example shows how a callAncestor statement can call handlers in the ancestor of a
behavior or parent script.
• This is the parent script:
-- script "man"
property ancestor
on new me, newTool
set ancestor = new(script "Animal", 2)
return me
end
on run me
put "Man running with "&the legCount of me&"legs"
end