EQWatcher Evolution > Scripting > Functions
An EQWatcher Evolution script function is a sequence of commands. Functions have the scope of a single script, and no two functions can have the same name. Functions can have parameters, local variables, and may return any value -- when returning a string, prefix the function name in the definition with a $ (also when importing, prefix the library name with $). Any function that has parameters MUST receive those parameters when it is called, or an error may occur. The compiler generally makes sure this works correctly, but I'm sure someone will find a way to break it. Functions may never have more than 7 parameters or 255 local variables. For extremely large functions you may want to break them down into smaller functions.
Functions are defined as follows:
Type 1] [Parameter Name 1],
[type 2] [name 2], . .
. [type 7] [name 7])
Name: Similar to variable names, function names must start with a letter, and contain only letters and numbers. Function names can be up to 254 characters in length without causing any problems. Function names ARE case sensitive!
Parameter Type: Parameters are variables, and therefore Parameter Types are exactly the same as Variable Types. Parameters are considered local variables, and may not be made public. When calling this function at any time, you must supply all parameters.
Parameter Name: Parameter Names are exactly the same as Variable Names as well.
Commands: Commands of course are all the script commands (NOT EQWatcher commands/aliases) you wish to execute within the function.
The first function of any script MUST be the "main" function, which is always run when the script is loaded. This function takes 0 parameters and generally would not return a value (the return value from main is not used). Any function has the option of returning a non-string value (unlike C, which functions are defined with a type, and only that type may be returned).
Here is an example of the main function definition:
unsigned long LocalVar2;
This example of course has no commands, since you aren't to the commands section yet, but two local variables are defined. Again, local variables may not be made public.
Aliases are defined as functions that may have NO parameters. They are defined as follows:
alias([Text to Match])
The Text to Match must contain the text you wish to turn into an EQWatcher command. Variables are used in this text using the @ and % modifiers explained in the Anatomy section on Variables.
Triggers can be defined as functions as well. If your triggers only play a sound, it is preferable to use the AddTrigger script command or the trigger addition aliases already defined. Triggers defined as functions are ever-so-slightly slower if they only play a sound.
The Text to Match must contain the text you wish to turn into an EQWatcher trigger. Variables are used in this text using the @ and % modifiers explained in the Anatomy section on Variables. When defining triggers this way or through AddTrigger, you MUST include the time and date stamp from the log file. The easy way to do this is precede the text with "[@trash@] ", which ignores the stamp altogether.
Please note that while trigger strings must account for the entire line from the log file, including the time stamp, aliases do not need to account for the stamp from the notes file.