Re: Script Objects - help please!!
Re: Script Objects - help please!!
- Subject: Re: Script Objects - help please!!
- From: Simon Forster <email@hidden>
- Date: Sun, 12 Jun 2005 13:17:26 +0100
On 10 Jun 2005, at 23:00, has wrote:
General point: I don't recommend using copy to duplicate nested
script objects as it's far too greedy. It doesn't just duplicate
the object and its contents, it also duplicates its parent as well
(in this case your entire library script), consuming considerable
resources and screwing up shared state (i.e. any mutable properties
in the library script which your script objects rely on). (Not that
duplicating some parent objects isn't desirable; just not the whole
damn lot of them.) Use a constructor function instead:
on makeRenderQueue(someData)
script
...
end script
end makeRenderQueue
set theList to {}
repeat...
set end of theList to makeRenderQueue(someData)
end
OK. Thank you. Taken on board and changed. Actually, I had it this
way at one point but in thrashing around trying to fix the problem I
was having, it got changed back.
While the subsequent references do not appear to be pointers to
the same object, when I call the object's getXX() method the
results are identical for both objects - the someData supplied to
the last object's init method.
[...]
Am I screwing up by having the script object in an external
library file?
Nope. This is one of the saner, more reliable parts of AppleScript.
So unless someone's broken it since I last used it then your
problem lies elsewhere. Unfortunately, you don't provide enough
code to recreate your bug which kinda makes it difficult to
diagnose. The only thing I can think of that'd cause the symptoms
you describe is if there's AppleScript references used somewhere in
your renderQueue object, as they're the one type of mutable
AppleScript object that the 'copy' statement does not duplicate.
Fine. So it's me (never any real doubt there though ;-)
If it's not that, you'll need to provide additional code so folk
can reproduce your bug themselves.
Thank you for your kind offer - but if I (try to) figure these things
out for myself, they're more likely to fix in the goo between my
ears. Anyway, your hints got me to re-look at my library code and it
transpires that I don't understand AppleScript's namespaces too well
(and I thought I'd got this figured out).
To ensure that the script objects's handlers were using (for both
setting and getting) the script objects's properties, I was declaring
these properties as globals within each handler - on the mistaken
belief that the handlers would use the script objects's (global)
properties. Instead it seems that we're using the top level script's
globals. I think I'm trying explicitly to control something
controlled automatically by AppleScript. i.e. If I'm referencing a
variable foo in a handler and that variable hasn't been declared
within the handler, it'll automatically look at the next level out -
the script's properties and/or globals.
Given this, how do I ensure that the handler will set the property
rather than create a new, handler level variable? In my testing,
referencing foo of me seems to work.
Anyone fancy taking on the task of explaining AppleScript's
namespaces with particular reference to how they work with respect to
script objects? Basic I know, but I don't seem to have this sorted
out properly yet.
TIA
Simon Forster
_____________________________________________________
LDML Ltd, 62 Pall Mall, London, SW1Y 5HZ, UK
Tel: +44 (0)70 9230 5244 Fax: +44 (0)70 9230 5247
_____________________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden