mIRC Home    About    Download    Register    News    Help

Print Thread
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.

Joined: Dec 2002
Posts: 5,482
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,482
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.

Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
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
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!


Link Copied to Clipboard