|
|
#1 |
|
Triple-A Player
Join Date: May 2003
Posts: 210
|
Initial value for global variables
Is this really necessary?
Code:
global chars
set chars to {"a", "b", "c"}
Code:
global chars {"a", "b", "c"}
Code:
property chars : {"a", "b", "c"}
__________________
Koala Surf Camp |
|
|
|
|
|
#2 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
Are properties not global?
|
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: May 2003
Posts: 210
|
Yes, but as I understand it - if you change a property first time you run a script, this changed value will apply next time the script is run. In other words, it won't be reset.
__________________
Koala Surf Camp |
|
|
|
|
|
#4 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
Will the value be changed in the script?
|
|
|
|
|
|
#5 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2002
Posts: 3,315
|
Apparently it is. But the only time it would matter (i think) is when the script has both a run handler and an open handler... and the run calls the open.
The way i do it (for the case i just mentioned) is to create a handler called INIT() and have both handlers call it right off the bat. Yes... there is a degree of redundancy involved, and maybe an if/then will be needed to avoid having the open handler trample on some values already set by the run handler. It all depends on what exactly the script does i s'pose.
__________________
chown -R us /your\ base/ -HI- . |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: May 2003
Posts: 210
|
Not in the current version. However, I have learned the hard way that constants should be constant. Sometime in the future one modifies the code and it breaks in an unexplainable manner.
__________________
Koala Surf Camp |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
All Star
Join Date: Mar 2006
Location: Littleton, Colorado, USA
Posts: 506
|
The global and local keywords describe the scope, but they don't initialize the variable. A property is a little bit of a different beast, more of an object characteristic (you can access a property from another script, for example), so it is initialized with a class and a value.
__________________
MacBook Pro / OS X Mountain Lion (10.8.3) / Xcode 4.6 / [various (much) older stuff keeping dust off the shelves] |
|
|
|
![]() |
| Tags |
| applescript, declaring variable, global variable, list, property |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|