At 3:50 PM +0100 9/22/00, sam wrote:
>What is the exact difference between a property and a (standard) variable -
>can you set global scope for a property?
>
Sam,
The scope of a global variable is anywhere in your whole Director
session. Once you set a global, it is available anywhere in the
current or any following movies. Just add a "global
gWhateverYourVariableNameIs" and you can set it or get its value.
A property variable is only available to any handler in the script
that defines the property variable (whether its a parent script or a
behavior). For example, consider the following parent script:
-- SomeParentScript
property pSomeProperty
on new me
pSomeProperty = 0
return me
end
on mIncrement me
pSomeProperty = pSomeProperty + 1
end
on mDecrement me
pSomeProperty = pSomeProperty - 1
end
Then assume that you instantiate an object from this parent script like this:
global gSomeObject
gSomeObject = new(script "SomeParentScript")
Now you have a global variable, gSomeObject, that is an "object
referece" to an instance of a SomeParentScript object. That object
has its own pSomeProperty. If you create another instance of the
SomeParentScript, then you will have another object that has its own
version of pSomeProperty.
The scope of each pSomeProperty is restricted to the handlers inside
the SomeParentScript script.
That being said, however, it is perfectly legal Lingo to "reach" into
an object to affect a property by using syntax like this:
gSomeObject.pSomeProperty = 5
or
someLocalVariable = gSomeObject.pSomeProperty
A few weeks ago, there was a long discussion here on Lingo-L about
whether you should or should not access properties declared in
objects directly. There was no clear winner to the discussion, but
people generally fell into one of three camps:
1) Pure OOP'ers. Whenever you want to "get" or "set" a property of
an object from outside the object, always add "accessor" routines
like these to your parent script (or behavior):
on mGetSomeProperty me
return pSomeProperty
end
on mSetSomeProperty me
pSomeProperty = pSomeProperty
end
2) Middle grounders. It's OK to "get" the value of a property of an
object, but not to set one. That is, it's OK to say:
someLocalVariable = gSomeObject.pSomeProperty
but to get the value of a property you should have a get method like:
on mGetSomeProperty me
return pSomeProperty
end
3) Fast accessors: It's OK to both "get" and "set" the value of a
property of an object by name.
I am a strong believer in #1 and would never get or set the value of
a property in an object directly. It seemed that many people felt
that #2 was right. And (if I remember correctly) a small percentage
were in camp #3.
Irv
--
Lingo / Director / Shockwave development for all occasions
(We even do weddings and Bar Mitzvahs!)
See our kid's CD-Rom's at: http://www.furrypants.com
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]