<doctitle>Scripting language syntax : aliases</doctitle> <docbody>

<docsubtitle>Aliases</docsubtitle>

> KVIrc supports definition of sub-procedures : aliases
> You can define an alias by using the built-in editor or by using the alias command.

> <example> alias saytoconsole { echo -w=$console $1-; } </example>

> In the above example we define the command "saytoconsole" that "echoes" the text passes as parameters to the console window.
> Now we can call it in the following way:

> <example> saytoconsole This text will go to the console window </example>

> Inside the alias there are few special identifiers:
> $0 : evaluates to the name of the alias
> $1 : evaluates to the first positional parameter
> $2...$9999999 : same as above but for the second, third.....parameter
> $# : evaluates to the number of the parameters passed.
> $1- : evaluates to all the positional parameters
> $2- : evaluates to all the positional parameters starting at the second one.
> $1-2 : evaluates to the parameters 1 and 2 $3-12 : evaluates to the parameters from 3 to 12

<docsubtitle>User definable functions</docsubtitle>

> KVIrc does not provide a direct way to create user definable functions.
> The function mechanism is emulated by aliases , the "bracket identifier" ${ } and the setreturn command.

> <example> alias sumthreenumbers setreturn $calc( $1 + $2 + $3) echo ${ sumthreenumbers 10 20 30; } </example>

> The example above will print 60 in the current window.
> setreturn sets the return value of the alias to the sum of the three numbers.
> The "${ }" identifier braces execute the command specified inside and evaluate to the return value of that command.
> You can execute more commands in the identifier braces and setreturn may be not called or called more than once.
> Obviously the last call defines the effective value returned by ${ }.
> Some other KVIrc commands set the return value.
> All the alias calls set the return value to the return value of the internal sequence of commands (alias propagates the return value).

> <example> alias propagate sumthreenumbers 15 5 20 echo ${ propagate } </example>

> In the example above "sumthreenumbers" sets the return value of the "propagate" alias.
> The parse command also propagates the return value.
> op , deop , ban and other similar commands return the number of messages effectively sent to the server.
> Bad example:

> <example> alias test setreturn 10; op Pragma; echo Opped Pragma; echo ${ test } </example>

> In the example above the setreturn command is useless: op resets the return value to 1 that is the number of MODE +o messages sent.
> echo does not modify the return value.

> In the help page of each command you will find the information about the return value.
> Seem complicated ? :)

Main index , Syntax index </docbody>

</docbody>