Calling functions

I was looking through older threads which helped me figure out how to call functions from other scripts–but I am stuck.

note: both scripts are in the same suite.


(* Common.script *)
function launch944 pc, nme, role
    connect pc
    Typetext WindowsKey, "r"
    ... (do other stuff)
end launch944
(* End Script *)


(* CenterScreenInitialization.script *)
start using "Common"
launch944 "F1", "HOST", "HOST"
(* End script *)

Running the first script produces:

Selection Failed in 0:00:00 STUnknownMessage ERROR: No Such Command: 'launch944' 

I actually had the code working once, but then it stopped and i had no recollection of what the correct parentheses were. I thought I had the call functional when I used this format: launch944(“F1”, “HOST”, “HOST”), but I read elsewhere that it should work as written above: launch944 “F1” “HOST” “HOST”

Anyone able to point out my stupid error?

This actually took me a few minutes to work out what the problem is – the “start using” part is a red herring that distracts from the actual problem, which is that you have defined a function, but are calling it as a command. A function has a return value and must always be called as part of a larger expression – the return value must be used. Just using the call as part of a “put” statement will satisfy this requirement, so if you changed your code to this it would work:

(* CenterScreenInitialization.script *)
start using "Common"
put launch944 ("F1", "HOST", "HOST")
(* End script *) 

If you don’t actually care about the return value, then you could convert your handler definition to the generic “to” form:

(* Common.script *)
to launch944 pc, nme, role
    connect pc
    Typetext WindowsKey, "r"
    ... (do other stuff)
end launch944
(* End Script *) 

which can be called as either a command (on its own without parentheses) or a function (with parentheses as part of a larger statement.) Or if you won’t have a return value at all you can define it as a command with the “on” syntax:

(* Common.script *)
on launch944 pc, nme, role
    connect pc
    Typetext WindowsKey, "r"
    ... (do other stuff)
end launch944
(* End Script *) 

Either of the above two examples could be called without parentheses as in your original code.