Date: Wed, 19 Jul 1995 05:52:37 GMT From: "Glenn M. Picher" <gplists@IBM.NET> Subject: Re: parameters to write just one functionThe general technique is called "parameter passing": theSprite is a parameter passed from your on enterframe handler.
You can verify the correct type of parameters with code like ...
if not integerP(theSprite) then
alert "theSprite is supposed to be an integer"
return
end if
Also, you can act on parameters and return a value to the calling function.
on squared(theNumber)
return (theNumber * theNumber)
end
put squared(2)
-- 4
set theResult to squared(2)
put theResult
-- 4
Finally, you can also pass a varying number of parameters and detect them
with the paramCount and param() keywords.
on multiplyAll
if (voidP(the paramCount) or (the paramCount <= 0)) then
alert "multiplyAll is supposed to be supplied numbers to multiply!"
return void
end if
put 1.0 into theResult
repeat with i = 1 to the paramCount
if not (integerP(param(i)) or floatP(param(i))) then
alert "multiplyAll's parameter " & string(i) & " isn't a number"
return void
end if
set theResult to theResult * param(i)
end repeat
return theResult
end
- Glenn M. Picher gpicher@ibm.net gmpicher@pilot.njin.net
- Roving multimedia programmer/artist; voice mail 502/745-0365
- Replies go to gplists@ibm.net Use gpicher@ibm.net for personal mail