mIRC Homepage
Posted By: Trax $rand gives the same value - 03/09/15 08:45 AM
Hello everyone! I hope someone will finally help me over here.
In the following command, I get the same value over and over again :

Code:
/timer 1 1 timercheck 0 2 msg #mirc $rand(1,20)


Why does it happen, and what should I do to get different values?

THANKS! grin
Posted By: westor Re: $rand gives the same value - 03/09/15 08:56 AM
use this: /timer 1 1 msg #mirc $rand(1,20)
Posted By: Trax Re: $rand gives the same value - 03/09/15 09:04 AM
the problem is - i need the two of the timers for a bigger script.
I can exchange the second timer for a "while" script, but i still get the same problem.
Posted By: westor Re: $rand gives the same value - 03/09/15 09:09 AM
I did not understand but if i get you try use this code:

Code:
alias safe return $decode($encode($1-, m) ,m)


and run the time like:

Code:
/timer[test] 0 10 echo -a Rand Number: $safe($rand(1,10))
Posted By: Trax Re: $rand gives the same value - 03/09/15 09:22 AM
well, it works fine without another timer.
when i try this command :
Code:
/timer 1 1 /timer[test] 0 10 echo -a Rand Number: $safe($rand(1,10))

i just get the same number over and over...
Posted By: westor Re: $rand gives the same value - 03/09/15 09:58 AM
Try use this:

Code:
//timer 1 1 timer[test] 0 10 echo -a Rand Number: $!safe($!rand(1,10))
Posted By: Trax Re: $rand gives the same value - 03/09/15 11:06 AM
It works!! Thanks!!
but why? blush
Posted By: Wims Re: $rand gives the same value - 03/09/15 01:52 PM
This is by design: http://en.wikichip.org/wiki/mirc/msl_injection#Nested_command
Originally Posted By: /help /timer
You can force identifiers to be re-evaluated when used in a /timer command by using the format $!me or $!time.
Posted By: Trax Re: $rand gives the same value - 03/09/15 05:28 PM
but it seems like :
Code:
/timer1 1 1 /timer2 1 1 msg #mirc $!rand(1,20)

wont work, but :
Code:
/timer1 1 1 msg #mirc $!rand(1,20)

would work
Posted By: westor Re: $rand gives the same value - 03/09/15 05:32 PM
Check my example above, you are missing the $!safe ...
Posted By: Trax Re: $rand gives the same value - 03/09/15 05:37 PM
yea, i know, but why should i use that? what does the $!safe do?
Posted By: westor Re: $rand gives the same value - 03/09/15 05:43 PM
If you read carefully our posts you wouldn't ask twice the same think the @Wims answered you above with an link, follow him and read the Wiki page that gave you to understand.
Posted By: Wims Re: $rand gives the same value - 03/09/15 06:39 PM
$safe isn't necessarily needed here, only if you have unknown content that are going to be evaluated 'twice' like that $rand, except $rand cannot return something dangerous.

timer1 1 1 /timer2 1 1 msg #mirc $!rand(1,20)

when you do that, the timer1 command will gather its parameter, what are the parameter of the /timer1 command here? it's "1" "1" "/timer2" "1" "1" "msg" "#mirc" "$!rand(1,20)"
$!rand(1,20) is an identifier, so it gets evaluated as "$rand(1,20)"

So the parameter of the /timer1 command are "1" "1" "/timer2" "1" "1" "msg" "#mirc" "$rand(1,20)"

And from that point, it will register that its associated command is "/timer2 1 1 msg #mirc $rand(1,20)", when that timer fires, mIRC execute:

/timer2 1 1 msg #mirc $rand(1,20)

Again, the paramater of the /timer2 command are gathered, $rand(1,20) is evaluated to let's say 6, and the associated command of that timer is "msg #mirc 6", you want it to be "msg #mirc $rand(1,20), if you have two nested timer, you want two '!!' : $!!rand(1,20) smile
Posted By: Trax Re: $rand gives the same value - 03/09/15 06:48 PM
Understood. Thank you very much!! grin
© mIRC Discussion Forums