Difference between revisions of "Timer"

From Scriptwiki
Jump to: navigation, search
m (Added a note about the way the time switch is used.)
m (no numbers as timername!)
 
Line 47: Line 47:
  
 
  alias timertest {
 
  alias timertest {
   timer1 2 10 echo -a [[$asctime|$!asctime]]
+
   timercorrect 2 10 echo -a [[$asctime|$!asctime]]
   timer2 2 10 echo -a $asctime
+
   timerwrong 2 10 echo -a $asctime
 
  }
 
  }
 
Here we create two timers, one with forcing it to re-evaluate the identifier (the one on top), the other not. You will see the first always echoing the current time, the other always echoing the time when it was started.
 
Here we create two timers, one with forcing it to re-evaluate the identifier (the one on top), the other not. You will see the first always echoing the current time, the other always echoing the time when it was started.

Latest revision as of 09:47, 15 October 2013

Activates the specified timer to perform the specified command at a specified interval, and optionally at a specified time.

/timer[N/name] [-ceomhipr] [time] <repetitions> <interval> <command>

If you are not connected to a server and a timer is started, it will be an offline timer by default, meaning that it will continue to run whether you are connected to a server on not. If you are connected to a server while starting a timer, it will be an online timer, that will stop if you disconnect. You can make a timer being an offline timer by using the -o switch.

To make a new timer, you can either use /timer without name/number or you can specify a name, without space between the command and the name (/timerfoo ...). If you do not specify a name/number, mIRC will get the first free timernumber it finds and use this.

If you specify a delay of 0 seconds, the timer will trigger immediately after the calling script ends.

You can also specify a time when the timer is supposed to trigger (see example below).

Note that if you specify 0 repetitions it will continue until you either stop it yourself or you disconnect, in case it is an online timer.

Note that identifiers usually do not get re-evaluated during a timer (see example below). To force this, you have to use an exclamation mark after the $ of an identifier (e.g. $!time or $!me)

You can stop a timer by using /timer<name|N> off, which will also be able to handle wildcards in the name (see example below).


You can use the following switches:

Switch Explanation
c will make mIRC "catch up" a timer by executing it more than once during one interval if the real-time interval isn't matching your requested interval.
m / h indicates that the interval delay is in milliseconds.
h make a high-resolution multimedia timer (uses system resources heavily)
e will executes the command associated with the specified timer name (works with wildcard names too).
p will pause a timer
r will resume a timer
i will make a timer dynamically associate with whatever happens to be the active connection. If a server window is closed, the timer is associated with the next available server window.

Example

In the following, we'll always create an alias to be able to execute commands directly after creating the timer.

alias timertest {
 timer 2 2 echo -a moo!
}

This alias just creates an timer that will echo moo! to your active window two times with a delay of 2 seconds.


alias timertest {
 timercorrect 2 10 echo -a $!asctime
 timerwrong 2 10 echo -a $asctime
}

Here we create two timers, one with forcing it to re-evaluate the identifier (the one on top), the other not. You will see the first always echoing the current time, the other always echoing the time when it was started.


alias timertest {
 timermilli -m 10 50 echo -a The difference is 50 milliseconds.
}

This timer called milli will echo The difference is 50 milliseconds. every 0,05 seconds to your active window, all in all 10 times.


alias timertest {
 timertime 14:00 1 1 echo -a It is 14:00 o'clock.
}

This one will echo It is 14:00 o'clock. to the active window when it is 14oclock, as we made the timer trigger then.


timer1* off

We just stop all timers beginning with a 1.

Notes

When using {, } and | in timers they will get evaluated before setting the timer so it is always advisable to avoid stacking commands inside of a timer.

Best practise would be to never try and stack commands inside a timer, instead create an alias with the commands you wish to run and start a timer to execute the alias.

timer 1 5 showme
alias showme {
  if ($true) {
    echo -ag My name is $mnick
    echo -ag And I eat fish.
  }
  echo -ag That go moo!
}

Although it should be avoided where ever possible it is possible to stack commands using $chr(124) as the command delimiter.

timer 1 5 echo -ag My name is $mnick $chr(124) echo -ag And I eat fish.
;;This will start a timer like this:
* Timer 1 1 time(s) 5s delay echo -ag My name is Dana | echo -ag And I eat fish. (QuakeNet)

It is also possible to use $chr(123) and $chr(125) instead of { and } for stacking commands in an if-then-else.

timer 1 5 if ($true) $chr(123) echo -ag My name is $mnick $chr(124) echo -ag And I eat fish. $chr(125) $chr(124) echo -ag That go moo!
;;This will start a timer like this:
* Timer 1 1 time(s) 5s delay if ($true) { echo -ag My name is Dana | echo -ag And I eat fish. } | echo -ag That go moo! (QuakeNet)

Take extra care when using the TIME switch with repeats. The time option is only used for setting the timer. Here is details of how the previously mentioned timed timer initiates.

timer 14:00 1 1 echo -a It is 14:00 o'clock.
;When when the time is 14:00, start a timer which runs once with a delay at 1 second.
;The result would be at 14:00:01 the echo would be displayed.

timer 14:00 0 1 echo -a It is 14:00 o'clock.
;When when the time is 14:00, start a timer which runs continually every second.
;The result would be at 14:00:01,14:00:02,14:00:03,14:00:04,14:00:05,... the echo would be displayed.

;If you wish to run a timer every day there is two options, either set the with a delay of one day or restart the timer.
timer 14:00 0 $duration(1day) echo -a It's 14:00!
;Using the above timer the echo would not run today but the duration amount 1day/86400 seconds after.
;To overcome that you can either set two timers like this:
timer 14:00 0 $duration(1day) echo -a It's 14:00!
timer 14:00 1 0 echo -a It's 14:00!
;Or if you're using an alias reinitialise the timer.
timer 14:00 1 0 showTime
alias showTime {
  .timer 14:00 1 1 showTime
  echo -a It's 14:00!
}

Avoid using timer [time] 0 0 as this is almost certainly going to be a mistake.

See Also

  • /timers to stop all timers, take a look at.
  • $timer to get information about a timer.