Starts a timer
timer [-s] [-p] (<name>,<delay_in_msecs>[,<callback_param1>[,<callback_param2>[,...]]])
Starts a new timer named <name> with the specified delay (in milliseconds).
The timer periodically calls the specified <callback_command> code passing the eventual <callback_param> strings as positional parameters.
If a timer with the same name already exists, it is replaced by this one.
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.
Using a very low delay is a common method to perform some background processing: you basically split a huge job in small slices and execute them when the timer is triggered until you run out of slices. A delay of 0 will cause the timer to be called whenever KVIrc has some "idle time" to spend. On the other hand, remember that timers are precious resources: many timers running with a very low delay will cause KVIrc to slow down.
Since all the kvirc timers share the same namespace it is a good idea to use descriptive timer names: a timer named "a" is likely to be used by two or more scripts at once causing one (or both) of them to fail.
A timer can be stopped at any time by using the killtimer command.
-s | --single-shot
Causes the timer to trigger only once (single shot timer)
-p | --persistent
Creates a persistent timer bound to any existing window
Syntax Specification
timer [-s] [-p] (<name>,<delay_in_msecs>[,<callback_param1>[,<callback_param2>[,...]]])

    # 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
        # 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)
            # This will kill the current timer, we don't need to specify the name
    # Use isTimer to check if the timer exists
    echo $istimer(test)
    # Repeat the command above after the 10th timeout...

See also

Index, Commands
KVIrc 3.9.99 Documentation
Generated by root at Wed Oct 17 19:34:06 2007