# timer

Starts a timer

Syntax

    timer [-s] [-p] (<name>,<delay_in_msecs>[,<callback_param1>[,<callback_param2>[,...]]])
    {
        <callback_command>
    }

Description

Starts a new timer named <name> with the specified delay (in milliseconds).
If a timer with the same name already exists, it is replaced by this one.
The timer periodically calls the specified <callback_command> code passing the eventual <callback_param> strings as positional parameters.
The <callback_command> is evaluated at timer "shot" time and NOT while this command is being parsed. This means that the identifiers that you put inside <callback_command> will NOT have the current values. The values will be assigned at timer "shot" time.
This is a common scripters error and problem: if it is not clear, look at the examples below.
The timer is bound to the window in that this command is executed in.
If the window gets destroyed, the timer is stopped; unless the -p switch is used.
The -p switch causes the timer to be persistent across the application and exists until the last window has been closed: it is basically rebound to another (random) window when the original window is destroyed.
The -s switch cuases this timer to trigger only once: it will be automatically destroyed after that.
The time has an associated set of extended scope variables: the variables that begin with "%:" have their life extended to the whole "life" of the timer.

Examples

        # Just a plain timer
        timer(test,1000){ echo "Hello!"; }
        # Now watch the timer running
        killtimer test
        # Single shot timer
        timer -s (test,1000){ echo "This will fire only once!"; }
        # The call above is equivalent to
        timer(test,1000){ echo "This will file only once!"; killtimer test; }
        # Callback parameters: consider the following code
        %parameter = "some string value"
        echo "Before calling /timer \%parameter is \"%parameter\""
        timer -s (test,1000,%parameter){ echo "inside the callback \%parameter is \"%parameter\" but \$0 is \"$0\""; }
        # watch the timer running , and note the behaviour of the %parameter variable
        killtimer test
        # Use the extended scope timer variables
        timer(test,1000)
        {
            # Use the extended scope %:count variable to keep track
            # of the times that this timer has been called
            if("%:count" == "")%:count = 1
            else %:count++
            echo "This timer has fired %:count times"
            if(%:count == 10)killtimer test
        }
        # Use isTimer to check if the timer exists
        echo $isTimer(test)
        # Repeat the command above after the 10th timeout...

See also
killtimer

Index, Commands

KVIrc 3.2.0 Documentation
Generated by root at Thu Mar 9 08:43:54 2006