Hi everyone,
I’m wondering about the message path within the front scripts. It seems like front scripts cannot use helpers to handle messages. The following yields an error message:
I have the following:
Main.script:
insert MyFrontScript into the frontScripts
MyMessage
MyFrontScript.script:
insert MyFrontScriptHelper into the helpers of me
MyFrontScriptHelper.script:
to handle MyMessage
put "Hooray, my message was handled"
end MyMessage
The “Hooray” is never printed. Instead, an STUnknownMessage exception is thrown. Does that seem right?
Thanks in advance for any advice or ideas for a work-around.
If you change MyMessage
to MyFrontScriptHelper.MyMessage
in Main, it will work as expected. Nested handlers need to be referenced as being contained within the parent handler, in this case the MyFrontScriptHandler script.
1 Like
Hi Dave,
thanks for your reply. However, it does not seem to be a solution to my problem.
Your suggested code seems to simply call the MyMessage handler in MyFrontScriptHelper directly. It works even if I insert nothing into the frontScripts and delete MyFrontScript entirely. Also, I cannot really make heads or tails of your comments regarding nested handlers within this context.
In other words, you seem to suggest the message path:
Main --MyMessage–> MyFrontScriptHelper
What I instead mean to do is use the following message path:
Main --MyMessage–> frontScripts → MyFrontScript → MyFrontScriptHelper
Fortunately, I think I have figured this out myself in the meantime.
It appears, that the initHandler of my original MyFrontScript was never called. Therefore, MyFrontScriptHelper was never inserted into its helpers.
Since I eventually mean to use newly allocated objects anyway, I have settled on the following solution:
Main.script:
// Insert into frontScripts a new object based on prototype MyFrontScript
insert new MyFrontScript into the frontScripts
MyMessage
MyFrontScript.script:
// Constructor of new objects registers MyFrontScriptHelper as helper object
to initialize
insert MyFrontScriptHelper into the helpers of me
end initialize
MyFrontScriptHelper.script:
to handle MyMessage
put "Hooray, my message was handled"
end MyMessage
I am glad that you found your solution.
Dave
1 Like
Another way of solving this would be to list the helpers directly in the script. That way you don’t need to write an initialize handler or depend on it being called. So, at the beginning of MyFrontScript.script you would just enter the following:
properties
helpers:["MyFrontScriptHelpers"]
end properties
Of course, since you say you’ll be creating instances of this object anyway, then using initialize is a perfectly good solution, too.