mIRC Home    About    Download    Register    News    Help

Print Thread
$rand gives the same value #254792 03/09/15 08:45 AM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
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

Re: $rand gives the same value [Re: Trax] #254793 03/09/15 08:56 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
use this: /timer 1 1 msg #mirc $rand(1,20)

Re: $rand gives the same value [Re: westor] #254794 03/09/15 09:04 AM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
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.

Re: $rand gives the same value [Re: Trax] #254795 03/09/15 09:09 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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))

Re: $rand gives the same value [Re: westor] #254796 03/09/15 09:22 AM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
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...

Re: $rand gives the same value [Re: Trax] #254797 03/09/15 09:58 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try use this:

Code:
//timer 1 1 timer[test] 0 10 echo -a Rand Number: $!safe($!rand(1,10))

Re: $rand gives the same value [Re: westor] #254798 03/09/15 11:06 AM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
It works!! Thanks!!
but why? blush

Re: $rand gives the same value [Re: Trax] #254803 03/09/15 01:52 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $rand gives the same value [Re: Wims] #254808 03/09/15 05:28 PM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
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

Re: $rand gives the same value [Re: Trax] #254809 03/09/15 05:32 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Check my example above, you are missing the $!safe ...

Re: $rand gives the same value [Re: westor] #254810 03/09/15 05:37 PM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
yea, i know, but why should i use that? what does the $!safe do?

Re: $rand gives the same value [Re: Trax] #254811 03/09/15 05:43 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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.

Re: $rand gives the same value [Re: Trax] #254814 03/09/15 06:39 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
$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

Last edited by Wims; 03/09/15 06:40 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $rand gives the same value [Re: Wims] #254816 03/09/15 06:48 PM
Joined: Sep 2015
Posts: 7
T
Trax Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Sep 2015
Posts: 7
Understood. Thank you very much!! grin