Congratualtions on your thesis!
In just looking over the versions of getPropertyDescriptionList from your post, both have errors. GPDL #1 says that you are trying to build a list of members, but what you are really displaying is a list of numbers. This is because you are just adding the value of the variable "j" to the list. "j" is really just an integer. Further, while you are iterating over the number of members of castlib "Assets", you are not checking the correct member in the if statement. Finally, for speed, you should always use a local variable when you have a repeat loop going up to some value which is returned from a function. In your case, 'the number of members of castlib "Assets"' will not change during the loop, so you should do the check once. The code should look more like this (untested):
property pVectorShape
on getPropertyDescriptionList(me) vectorShapesList = [] nMembers = the number of members of castlib "Assets" -- do this once here repeat with j = 1 to the nMembers if(member(j, "Assets").type = #vectorShape) then vectorShapesList.add(member(j, "Assets")) end if end repeat descriptionList = [:] descriptionList.addProp(#pVectorShape, [#comment:"Which one", #format:#member, #range:vectorShapesList, #default:1]) return(descriptionList) end
GPDL #2 has two errors. First, in your repeat loop you are trying to access member(j, i), but "i" has no value. Then, you are trying to add to the vectiorShapesList a variable called "theName" but that is not defined either.
However, I believe that your general question is really about when you should use a variable to store results of a function. You should always use one if you are going to re-use the value multiple times and the value doesn't change (as in the description above). However, the other case that you describe has to do with using a local variable versus just using the results of a function directly. The answer is that it really is up to you. It really is a matter of style. Here's an example:
on someHandler
someVariable = function1(someParam) + function2(someOtherParam) + someOtherVariable
end
versus:
on someHandler f1Result = function1(SomeParam) f2Result = function2(SomeOtherParam) someVariable = f1Result + f2Result + someOtherVariable end
You will get the same answer whether you do, or do not use a local variable. The main reasons to use local variable(s) are for clarity and debugging. I personally like to use local variables for intermediate results for debugging purposes. If you store some intermediate result into a local variable, you can set a breakpoint right after a call to a function and ensure that the function is returning the value you expected. It really helps track errors down quickly. Further, by splitting things up into multiple lines like this, I often find it easier to read.
Others disagree with me and try to pack as much into a single line as possible.
Using local variables will be slightly more expensive time-wise, but unless the function calls are made millions of times, you will never notice a slowdown by using an additional local variable.
Irv
At 10:30 PM +0300 6/7/04, Peter Bochan wrote:
Hello,
First, I'm very happy as I managed to defend my M.A. thesis to an excellent mark. Second, I'm a bit confused: when do I use variables and when do I use functions straight ahead?
E.g. I wanted to make a handler that would check for definite members in definite castLib and then add the results to the list. When I tried to use this:
<snip> --
Multimedia Wrangler.
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/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!]