mIRC Home    About    Download    Register    News    Help

Print Thread
#225811 10/09/10 10:12 AM
Joined: Sep 2007
Posts: 202
F
firefox Offline OP
Fjord artisan
OP Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
let's say that I have

%var1 test1
%var2 test2

and I run /timer 1 10 /alias %var1 %var2

everything works fine

but if before the 10 seconds have finished the values change to:

%var1 test3
%var2 test3

when the time ends and calls the alias it uses the new values - how do I make it use the values of the vars when the timer was actually started?

Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Run this bit of code before reading my explanation:

Code:
alias1 {
  echo -a setting variables
  set %x test1
  set %y test2
  .timer 1 5 alias2
  .timer 1 10 alias3 %x %y
}

alias2 {
  echo -a changing variables
  set %x test3
  set %y test4
}

alias3 {
  echo -a var x: %x
  echo -a var y: %y
  echo -a para 1: $1
  echo -a para 2: $2
}


When you use %var1 and %var2 as parameters in the timer command, they will arrive in that alias as $1 and $2 respectively, representing the first and second parameters sent along (assuming for the moment neither variable contains any spaces).

However, I'm assuming that your new alias reads %var1 and %var2 again, which indeed have been updated. Use $1 and $2 to check the variables as they were when you initiated the timer.

EDIT: Also, if %x would be $null, then you'd get %y as $1, since that would become the first parameter.

Last edited by Thels; 10/09/10 10:23 AM.

Learning something new every day.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Variables are evaluated at the moment the timer is triggered.

You can simply prevent pre-evaluation by using $(%var1,0) - $() is similar to $eval()

This way %var1 will literally be passed to the alias as $1 and only be evaluated once the alias is called.

Edit: You can achieve this same result in various ways of course. Another method is using $+(%,var1)

Last edited by 5618; 10/09/10 11:35 AM.
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
I think Khaled made it so you can put a ! after the command symbol to evaluate it when it executed.

timer 1 1 alias %!var1 %!var2 $!alias(%!var1,%!var2)

Is this right?

Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
It doesn't work with variables, only with identifiers.

%!var1 is actually a variable on it's own, separate from %var1.

I'm also not sure they work with timers. They were meant for scid, IIRC.


Learning something new every day.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
The command part of a timer will be evaluated on execution. However, the timer command will be evaluated as issued as well. Some of the methods to prevent that "first" evaluation (at the moment the timer command is issued) for variables:
Code:
//set -u3 %x 1 | timer 1 1 echo -a evaluated at timer start: %x // evaluated at timer end: $(%x,0) or % $+ x or $+(%,x) | set -u3 %x 2


for identifiers:
Code:
//timer 1 1 echo -a evaluated at timer start: $time(ss) // evaluated at timer end: $($time(ss),0) or $!time(ss) or $ $+ time(ss) or $+($,time(ss))


In several situations the "double evaluation" of timers (and of some other commands) may not only result in unexpected values, but become a security issue. Here are two further methods (especially useful for unknown strings or lengthy commands).
Another method would be to put your parameters not in the command part of a timer but in it's name (then use e.g. token identifiers on $ctimer).

Finally - it's the most obvious sollution for your initial example - you may have the timer call "/alias" only and store your values/parameters in global variables, hash tables, or the like.

Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
From what I understood, he actually wants them to evaluate when the timer starts, which makes me thinks he refers to the variables again, instead of $1 and $2.


Learning something new every day.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Too bustling to add to the other... reading it again, you're right wink


Link Copied to Clipboard