Re-usable Procedures

From HLKitWiki
Revision as of 03:48, 18 November 2008 by Rob (Talk | contribs) (New page: Category:Basic Concepts and Terminology [Context: HL Kit … Basic Concepts and Terminology … Scripting Language] Procedures provide the means to define scrip...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[Context: HL KitBasic Concepts and TerminologyScripting Language]

Procedures provide the means to define script logic in a single location and re-use that logic within multiple scripts by calling the procedure from each of those scripts. Procedures are an extremely convenient tool and are used regularly for various purposes.

script type vs. context - controls access to special symbols

pick and container procedures for re-use with preserved context

generic allows use with any script

inherit the context of the caller

However, procedures also have a variety of special characteristics that must be properly accounted for by an author. Those characteristics are outlined below.

  1. Procedures have no parameters, so you cannot pass parameters to procedures in the way that traditional programming languages do so.
  2. Procedures inherit all local variables of the calling script. You do still need to declare these local variables within the procedure so that the compiler knows how you intend to use them, but their values will be inherited when the procedure is called. Using local variables, you can pass information between the calling script and the procedure. Changes made to variables within the procedure will remain in effect upon return to the calling script, so you can use this technique to pass information in either direction between the script and procedure.
  3. All procedures must be assigned a classification (or context). Scripts can only call procedures that are assigned a compatible classification. For example, you cannot call a procedure with "container" context from within an Eval Script, since that script has a "pick" context.
  4. Procedures are not allowed to call other procedures at this time.
  5. If a procedure is designated as having a specific script type, then you can access the exact same special symbols from within the procedure that can be accessed by that script type. These special symbols inherit they meaning from the calling script, just like variables.
  6. Procedures can also be declared as generic, in which case no access to special symbols is possible from within the procedure. The advantage of a generic procedure is that it can be called from scripts of different types, but it comes with this critical limitation. If you need to access a special symbol from within a generic procedures, the calling script must declare a local variable and copy the special symbol value into it prior to calling the procedure.