mIRC Home    About    Download    Register    News    Help

Print Thread
Unexpected timer set var behaviour #267808 04/10/20 10:45 PM
Joined: Oct 2020
Posts: 2
Moros Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Joined: Oct 2020
Posts: 2
I've been troubleshooting a script error for quite some time and the problem seems to stem from the way some variables are reevaluated when set by a timer.

Example 1:
//set -s %test.var $eval($file(mirc.exe).version,0) | set -s %new.var %test.var

Expected return:
$file(mirc.exe).version
$file(mirc.exe).version

Example 2:
//set -s %test.var $eval($file(mirc.exe).version,0) | timer 1 1 set -s %new.var %test.var

Unexpected return:
$file(mirc.exe).version
7.63.0.0

timer 1 1 set -s %new.var $eval(%test.var,0) gives me the desired result, but I don't recall ever seeing this mentioned in the documentation.

Re: Unexpected timer set var behaviour [Re: Moros] #267812 05/10/20 09:05 PM
Joined: Dec 2002
Posts: 4,829
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,829
That is indeed the way /timers work. If you want to pass the non-evaluated form of the variable or identifier, you need to use $eval(), [], $+, $!, or various combinations of these.

Re: Unexpected timer set var behaviour [Re: Moros] #267817 06/10/20 01:06 PM
Joined: Apr 2004
Posts: 853
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 853
Originally Posted by Moros
timer 1 1 set -s %new.var $eval(%test.var,0) gives me the desired result

Here you are preventing evaluation when you start the timer, which indeed works, but keep in mind that whatever you pass in then still has to be valid at the time that the timer triggers. For example, if you unset %test.var before the timer triggers, you will end up with nothing. That may or may not be what you want; often, it is not. When passing in something like a local variable or $1-, preventing evaluation when starting the timer will not work: when the timer actually triggers, the context in which that variable or identifier was valid will be gone.

Alternatively, you can prevent evaluation when the timer triggers. Usually that is a better approach, and also easier: mIRC has a built-in identifier for that, namely $unsafe. For example:

Code
//set -s %test.var $eval($file(mirc.exe).version,0) | timer 1 1 set -s %new.var $unsafe(%test.var)


Saturn, QuakeNet staff
Re: Unexpected timer set var behaviour [Re: Sat] #267828 07/10/20 03:31 AM
Joined: Oct 2020
Posts: 2
Moros Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
Joined: Oct 2020
Posts: 2
Thank you for that clear explanation!