Re: Scope
Re: Scope
- Subject: Re: Scope
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 14 Dec 2002 12:02:55 -0800
On 12/13/02 12:44 AM, "Emmanuel" <email@hidden> wrote:
>
At 12:56 PM -0800 12/12/02, Paul Berkowitz wrote:
>
>
> tell g to set var3 to anotherHandler(var1)
>
>
I suspect a matter of scope, like you do, and I would really try
>
>
tell g to set var3 to anotherHandler(A's var1)
>
>
I am familiar with this kind of problem. If (in Smile) some object's
>
script owns some property "p", then if its handlers are called only
>
from the object's script I need no special precaution, I may use
>
simply "p" in the script. But if the handlers are supposed to be
>
called from another [object's] script, it is necessary that I specify
>
whose p that is:
>
>
[script of the called object]
>
property p:""
>
>
on DoIt(theObject) -- thus it's better to always pass that reference
>
-- use "theObject's p" always
>
end
Emmanuel was right. It does turn out to be something of this sort. But
trickier. I actually got the error once myself, made a change in the script
and now no longer get it. But other users do. So it's inconsistent, and I
don't know what to do about it. It was also obscured by this fact:
set fi to missing value
set c to count fi
display dialog c
--> ERROR: "0 doesn't understand the count message."
That's the error message everyone is getting, and I couldn't figure out
where the "0" was coming from. It's coming from 'missing value'. OK.
Here's the setup. I had split a very long script into two (three, actually,
but we can discount the third part) because of the bug in AS 1.9 with long
scripts. I need a lot of properties and some globals for once because I have
to have access to their values if the script errors due to corrupt data: the
error is trapped wherever it occurs is and sent to an error handler which
relays information about the faulty items, derived from the current values
of these properties, to the user. That part works fine. So it means that
these particular properties can't be passed as parameters through all the
handler circuitry, of course. They're global in scope and can just be
accessed.
Now, when splitting the script, I had to make them as properties at the top
the loaded assistant script (script "B" - a compiled script library), so
that all the handlers in script B could continue to access them. What I did
in script B was this:
[script B]
property var1 : missing value
property var2 : missing value
property var3 : missing value
on ControllerHandler(var4, var5)
--do lots of stuff, call Handler1()
return {var1, var2, var3}
end ControllerHandler
on Handler1()
try
--do stuff with var1, var2
on error
display dialog "Alert problem"
set end of var3 to "some info"
end try
end Handler1
----------------------
Back in the main script applet "A", because there are so many properties to
pass to script B (more than the 3 above), I do that first, before calling
script B's ControllerHandler:
[script A]
---------------------
property var1 : 1
property var2 : 1
property var3 : {}
set var4 to "something"
set var5 to "something else"
--stuff that changes var1, var2, maybe var3
set f to load script alias "path:to:script B"
tell f
set {its var1, its var2, its var3} to {my var1, my var2, my var3}
set {my var1, my var2, my var3} to its ControllerHandler(var4, var5)
end tell
display dialog "All done!" & return & var1 & return & var2
if var3 /= {} then
repeat with i from 1 to (count var3)
set anItem to item i of var3
-- parse the data and put it into a text file
end repeat
display dialog "Info about problem items in text file"
end if
-------------------------
The script works perfectly, using all the passed values in script B and
passes them back to script A. Nobody is getting any alert about problems in
script B. Everything is fine so var3 should remain at {} in both scripts.
Everyone gets the "All done!" message, with accurate values for var1 and
var2. As soon as they click "OK", they get:
ERROR: "0 doesn't understand the count message."
When I got that once, I changed the 'tell f' in script A to:
tell f
set {its var1, its var2, its var3} to {my var1, my var2, my var3}
end tell
set {my var1, my var2, my var3} to f's ControllerHandler(var4, var5)
That seemed to fix it for me, but for no one else. Most users are still
getting the error.
**THE PROBLEM:
What seems to be happening is that the 'missing value' properties in script
B do get set to the passed values, and get used by script B. The script
would break otherwise. But because var3 never once gets modified during
script B's run (as long as there are no faulty data items there) it does not
seem to be "registered" properly by the ControllerHandler there. So when it
retuns
{var1, var2, var3}
to the main script, it returns the properly modified values for var1 and
var2 (which could only be modified if it first had its var1 and var2 re-set
from missing value to the values passed by script A in the first place), but
instead of passing back
{}
or var3, the value passed to that property by script A before any handler
was called, it returns
missing value
its _unmodified_ initial value before script A passed the {} value to it!
So the 'if' block the the very end of the script A runs, since var3 is now
'missing value' rather than {} as it's supposed to be, and then when it
tries to 'count var3', it can't count 'missing value' so you get the
mysterious '0 doesn't understand the count message' error.
This is very bad. It seems like a bug to me. How can I make sure that this
doesn't happen? Perhaps start ControllerHandler by
set {var1, var2, var3} to {var1, var2, var3}
or
set {my var1, my var2, my var3} to {my var1, my var2, my var3}
to "initialize" them?
Or, instead of trying to set script B's properties directly from script A,
include a handler in script B:
on SetProperties(a, b, c)
set {var1, var2, var3} to {a, b, c}
end SetProperties
and call that handler from script A first of all
tell f to SetProperties(var1, var2, var3)
Has anyone experience with this stuff? It's tricky to test, because I don't
even get the error at the moment although many of my users do.
Thanks for any insights anyone can provide.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Re: Scope (From: Emmanuel <email@hidden>) |