Re: help needed-- probably a scoping problem
Re: help needed-- probably a scoping problem
- Subject: Re: help needed-- probably a scoping problem
- From: email@hidden
- Date: Mon, 21 May 2001 15:47:12 -0400
On Sat, 19 May 2001 08:23:10 -0700
Ken Victor <email@hidden> asked,
>
i have a script that basically is as follows:
>
>
script main
>
property a : missing value
>
property b : missing value
>
>
on run
>
---
>
(* set properties a and b to some values *)
>
--
>
end run
>
>
on initProperties()
>
(* set properties a and b to some values *)
>
end initProperties
>
end script
>
>
run
>
-- time 1
>
display dialog ("time 1 property a = " & ((a of main) as string))
>
display dialog ("time 1 property b = " & ((b of main) as string))
>
>
initProperties() of main
>
>
-- time 2
>
display dialog ("time 2 property a = " & ((a of main) as string))
>
display dialog ("time 2 property b = " & ((b of main) as string))
>
>
run script main
Change the line above to "tell main to run"
>
>
-- time 3
>
display dialog ("time 3 property a = " & ((a of main) as string))
>
display dialog ("time 3 property b = " & ((b of main) as string))
>
end run
>
>
at time 3 however, the dialogs show both variables to have the same
>
values that they had at time 2 and don't reflect any changes made by
>
running the script main. this is not what i was expecting and is
>
causing me all sorts of problems. am i doing something wrong? is this
>
a scoping problem of some sort? and if so, could someone please
>
explain this to me?
Essentially, the "run script" command (from Standard Additions) runs the script
in a separate context. Essentially, it makes a copy of the script object and
puts it in its own box. That means changes to properties don't appear when you
ask the original script object for them. You see the original properties,
before the "run script"
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden