One nice new feature in Authorware 6.5 is that you can write your own functions. This means that you can have one copy of your code and call it over and over throughout your Authorware file. We have always had subroutines, but this takes it a step further. You can call a function without navigating anywhere. What's more, you can store functions in an external file or database, and have a single copy that you use throughout a number of Authorware files.
For instance, imagine that you often have to convert a list to a return-delimited string. You might create a function icon that is called ListtoString. Creating a function icon is as simple as checking "Contains function" in a calculation's Icon Properties.
The function itself might contain something
like:
repeat with element in args@"ListtoString"
if Output = "" then Output := Output^Return
OutPut := Output^element
end repeat
result@"ListtoString" := Output
You'll notice when you do this that Authorware will ask you to define args@"ListtoString" and result@"ListtoString."
To call the function, all you need to do is include the line CallScriptIcon@"ListtoString", mylist) in any calculation, anywhere in the Authorware piece.
This should work great for internal functions, but will fail if you use it with a script string or script file. The reason for this is that there is no longer an icon called "ListtoString." For starters, you would need to change all references to that icon to @IconID. That won't fix the problem, though, because now the IconID referred to is whichever calculation happened to call the script icon. Args and result must exist for every calc that could call an external script function.
Because of this, my default calculation icon in Authorware 6.5 already has the args and result variables set up. You can do this easily by clicking on a calculation icon on the flow line and opening the variables window. Scroll down to the name of the calculation in the variables window, and create new variables named "args" and "result" by pressing the "New" button.
In addition, you need to make sure the variable
"Output" exists in the calling piece.