Something like this:
on MyFunctionName (myFirstParam,mySecondParam,etc..)
--code goes here
return MyReturnValue--this line is only neede if you want to return a value
end MyFunctionName
to call the function use:
MyFunctionName (myFirstParam,mySecondParam,etc..)
if there is no return value, or
MyVariable = MyFunctionName (myFirstParam,mySecondParam,etc..)
to set myVariable to the return value.
You will automatically return to the calling script.
Chris.