Re: Newbie Question: Script Objects
Re: Newbie Question: Script Objects
- Subject: Re: Newbie Question: Script Objects
- From: has <email@hidden>
- Date: Wed, 19 Feb 2003 22:35:36 +0000
Simon Brown wrote:
> - Properties of a script object retain their contents until the
script object is destroyed.
and
Script objects can survive the death of their host process.
When exactly are script objects destroyed? Is there not a difference in
lifespan between:
1) script objects declared WITHIN the current script or app
2) script objects declared WITHIN a particular handler inside the current
script or app.
3) script objects initialised on loading from an external file
A script object is a script object is a script object. Like any
value/object, it's disposed of when it's no longer in use. e.g. An
object held in a local variable in a handler is disposed of after the
handler returns if it's not the return value. And everything gets
chucked when the host process quits (or, in the case of an editor,
when the editing window is closed or recompiled).
Fortunately, AppleScript allows you to dump a flattened copy to disk
before this happens. Again, some slightly dodgy 3am wording in my
original statement may have confused the issue more than it helped:
the original script object doesn't survive, but an exact copy does.
Beyond this, you're into metaphysical debate of the "if I grow an
exact clone of myself and copy my consciousness into when my old body
dies, is this new 'me' really 'me' or not?" sort [1]. But hey, it's
good enough for me. :)
I'm still trying to work out how I've misunderstood the bit I quoted
previously from p318 of ASLG.pdf:
> The value of the property currentCount persists until you reinitialize the
> script object by running the script again.
Because this text [p317 in my copy] is incorrect for the code it
refers to. (Feel free to file a bug report on this, btw.) In that
code, the script object 'Joe' is initialised when the script is
compiled, and will remain in existence until the script is recompiled.
The text would've been correct if the code were written as:
======================================================================
on run
script Joe
property currentCount : 0
on increment()
set currentCount to currentCount + 1
return currentCount
end increment
end script
tell Joe to increment() --result: 1
tell Joe to increment() --result: 2
end run
======================================================================
In this case, 'Joe' is initialised each time the script is run [2].
But this code is not the same as, nor equivalent to, the code shown.
HTH
has
[1] I can't help you there, being neither philosopher nor Raelian.
[2] I won't mention when it gets disposed of though, as AppleScript
'run' handlers live in a bizzare little world all of their own.
(Masochists should refer to earlier discussions on that subject.)
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.