mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2004
Posts: 54
Z
Zed Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Mar 2004
Posts: 54
When a timer id is a number instead of text, $timer() doesn't work.

Try these 2 lines (in a status window) and you'll see what I mean:

//.timertest 1 1 echo -gs timer: $!ctimer - $!timer($ctimer) - $!timer($ctimer).com -- "test"
//.timer777 1 1 echo -gs timer: $!ctimer - $!timer($ctimer) - $!timer($ctimer).com -- "777"

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Originally Posted By: /help $timer
$timer(N/name)
Returns the timer id of the Nth timer in the timers list. You can also specify a timer name instead of a number.
It's thus no bug but rather by design. Simply dont use a N as the timer name if you're ever going to use that identifier smile

It's like naming an alias N and using it as a custom identifier:
Code:
alias 777 { $iif($isid,return,echo -a) test }
//777 | echo -a return is: $777

...or like naming a scriptfile "4" and attempting to get $script(4), or adding "0" as highlight text and $highlight(0).sound, or several similar cases I did not think of.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Although it would be better if there was some kind of switch in $timer() to denote that you were referring to a timer by name.

$timer(777,n) for instance


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Mar 2004
Posts: 54
Z
Zed Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Mar 2004
Posts: 54
Originally Posted By: Horstl
It's thus no bug but rather by design. Simply dont use a N as the timer name if you're ever going to use that identifier smile

It's like naming an alias N and using it as a custom identifier:
...

No, it's like using /timer without any timer id, and letting mirc increment the counter. wink
But the generated timer id is not the same as the timer's position in the $timer() list. And the script called by the timer can't easily get information about its timer with the $timer() identifier (unless it loops through all names with $timer(i) to locate the timer's "N").

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Yes, well, as I said, it would be better if mIRC had a switch to make both cases possible, but..

The automatic timer naming functionality in mIRC is a convenience for the simple case (a one-off timer to message someone or something). You should not rely on this functionality for scripts, especially those that need to access $timer(NAME) --for this very reason.

Similarly, you should consider numeric timer names as "reserved" in mIRC for the above simple case "auto increment" timer names. As such, you should not try to name any timers in this "namespace", since it is reserved for said timers. Of course, this is not a rule, just something of a convention. The easy fix here is to just name your timer something that is not numeric, as was mentioned, and stay away from stepping on mIRC's toes.



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Mar 2004
Posts: 54
Z
Zed Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Mar 2004
Posts: 54
Originally Posted By: argv0
Similarly, you should consider numeric timer names as "reserved" in mIRC for the above simple case "auto increment" timer names.


I don't use numbers as timer names. I left that for the automatic numbering. I have used 777 in my example to ensure that the timer will not be given a slot number equal to its id.
I use named timers (with ou without a $cid part) mostly for specific timers that need to be run only once.

The confusing part with $timer(N/name) is the difference of behavior compared to /timer[N/name].

/timer always handle the [] as a name, not as a slot number.

example:
/.timertest 1 1000 echo -gs timer test
/.timer 1 1000 echo -gs timer numbered

"test" is in slot #1
"1" is in slot #2

//echo -gs $timer(1)
outputs "test" (slot #1)

/timer1 -e
ouputs "timer numbered" (timer named "1" in slot #2)

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
The help file says /timer[N/name] because you can use a name or a number to identify a timer, /timer1 doesn't mean the first timer in mIRC's internal list ($timer(1)), it means the timer that has the number 1 as id.

Quote:
$timer(N/name)
Returns the timer id of the Nth timer in the timers list.
Here, the N is the number for the mIRC's internal list so yes, as said, it's impossible to directly access an information about a timer which has a number for id.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Originally Posted By: Wims
...so yes, as said, it's impossible to directly access an information about a timer which has a number for id.

$timer(timer1) works fine. This is not the format returned by $ctimer though.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
The timer in the above examples is named "1", not "timer1". Accessing a timer named "1" with $timer(timer1) does not work.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
From experience I thought that prefixing a timer name with "timer" was the same as just using the name.
However, I just tested it by downloading a copy of mIRC and you are correct in saying this is not the case.

I agree that timer names should not be numeric in nature, but an n-paramter as was suggested would perhaps be more elegant solution.


Link Copied to Clipboard