This content has been marked as final. Show 4 replies
> I am trying to execute a simple "do" command in a loop.
> repeat with flagCount = numberLayers down to 1
> toExecute = "layer" & flagCount & "Flag = 1"
> do (toExecute)
> end repeat
> I put in a breakpoint, and the 'toExecute' variable has the correct string in
> each iteration, but for some reason no flag is ever set to 1. It is almost as
> if it is ignoring the whole line.
Use of the "do" command almost always screams "there's a better way to
achieve this". In the above case a linear or property list.
That being said, perhaps you need to elevate your flags to _global:
toExecute = "_global.layer" & flagCount & "Flag = 1"
The reason I was trying to write it in a loop was that the number of layers will be different every time (and won't be known until the program loads up and reads the input files)....
Is there a better way to do this that I'm just not thinking of?
> Is there a better way to do this that I'm just not thinking of?
Perhaps. You could maintain a (global?) property list and add
propName:value entries to it as needed. But I don't know your specific
implementation or requirements. Can you put what you're doing into context?
You could create a property list, and set the values of the properties to 0 or 1:
if ilk(gFlags) <> #propList then
gFlags = [:]
i = numberLayers
repeat with i = 1 to numberLayers
The above code assumes that gFlags and numberLayers are declared as globals or properties, as appropriate.
To check if the flag corresponding to layer 1 is set:
if gFlags.getaProp(1) then
-- do stuff
If the number of flags is arbitrary, you may need to check that the layer number is not greater than the number of flags.
The example uses a property list, but a linear list would probably work just as well. You'd need to use setAt() and getAt() instead of setaProp() and getaProp(). Alternatively, you could use more meaningful property names than I have done.