can a subroutine alter a variable?
[using OSX - 10.2.8]
Sorry if I've misunderstood...
I'm getting confused. I'd like to pass a Boolean (initialised as false) as
on of my routine parameters - the name will vary per call:
set sFu to {"w","x"}
set sBar to "xyz"
set blnA to false
StringCheck(sFu,sBar,blnA)
display dialog blnA
set sSna to {"*","#"}
set sFu to "abcd"
set blnB to false
StringCheck(sSna,sFu,blnB)
display dialog blnB
on StringCheck(sArgA, sArgB, blnState)
repeat with sChar in sArgA
if sArgB contains sChar then
set blnState to true
end if
end repeat
-- return blnState
end StringCheck
This routine inherits all 3 variables but doesn't change, for example, blnA
to 'true' as I'd expect. I can ********ly "return blnState" and then set
blnA (or whatever) to than value but that seems very long-winded. I've also
tried setting "property blnState : false" at the head of the script but I
still can't get a 'true' return except via setting the main script to the
routine's 'return' value
It also begs the question about whether sub-routines can change the value of
variables passed from a higher scope. Or are 'Boolean's a special case. If
I was setting 2 Booleans in the sub-routine, how would I retrieve their
values as I understand writing (in the above)
end repeat
return blnStateOne
return blnStateTwo
end StringCheck
would result in the 'return' value of the routine being the value of
blnStateTwo. No?
On the wider horizon, I've learn a lot from the PDF of the advance sample
chapter of O'Reilly's "AppleScript - The Definitive Guide". The sample
chapter just happens to be on variables! It doesn't help with the above
though - as far as I can figure it out. (However, based on what I've read
I'm going to get a copy when it comes out sometime this month - Nov 03)
TIA
Mark
|