mIRC Home    About    Download    Register    News    Help

Print Thread
help with timers #177307 23/05/07 10:12 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Code:
alais test {
  var %c 1
  while (%c <= $chan(0)) {
    .timer $+ $chan(%c)) 1 $calc(2* $chan(0)) echo -a -> $chan(%c)
    inc %c
  }
}

This working ok, how ever it trigger the part echo -a -> $chan(%c)) way to fast, and i dont know how i can slow it down, been trying without any luck, ideas? i want it to send the echo with 5 secs appart..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: help with timers [Re: sparta] #177311 23/05/07 10:58 AM
Joined: May 2007
Posts: 23
C
chiram Offline
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 23
think you need to change the calc to multiply 5 by %c not 2 by $chan(0)

Code:
alias test {
  var %c = 1
  while (%c <= $chan(0)) {
    .timer $+ $chan(%c) 1 $calc(5 * %c) echo -a -> $chan(%c)
    inc %c
  }
}


edit: err removed the extra ) after bekars post

Last edited by chiram; 23/05/07 12:17 PM.
Re: help with timers [Re: chiram] #177315 23/05/07 11:45 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Two things to note though..

First, 'var' should have an '=' if you assign it a value, i.e.

Code:
var %c = 1

The second is there's a stray ')' in the timer name.

For interest, I usually do loops the other direction, as it doesn't need to equate $chan(0) so often:

Code:
var %c = $chan(0)
while (%c) {
  <code>
  dec %c
}

Anyway smile

Re: help with timers [Re: Bekar] #177318 23/05/07 02:06 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Doing reverse loops is ok when the order of the count is unimportant. If the order matters, then you can simply use a second variable to hold the top-end value. I also usually organize the commands so the /inc is the first command within the while loop. This allows you to use the /continue command without having to put an extra /inc with it each time.

Code:
var %c = 0, %cc = $chan(0)
while (%c < %cc) {
inc %c
;commands here
}


-genius_at_work

Re: help with timers [Re: Bekar] #177377 24/05/07 08:55 AM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Originally Posted By: Bekar
First, 'var' should have an '=' if you assign it a value, i.e.


Not true, var works fine without an equals sign, although probably not with multiple variables in a single /var, as genius has done.


NaquadaBomb
www.mirc-dll.com
Re: help with timers [Re: NaquadaServ] #177378 24/05/07 09:03 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Quote:

Local Variables

Local variables are variables that exist only for the duration of the script in which they are created and can only be accessed from within that script. They can be created with the /var command:

/var %x

This creates the local variable %x in the current routine and can only be referenced from inside this routine.

/var %x = hello

This creates a local variable %x and assigns it the value hello.

You can create multiple local variables by separating them with commas:

/var %x = hello, %y, %z = $me

loop {
var %x = 1
:next
echo item %x
inc %x
if (%x < 10) goto next
}

Note: You can use /var -s to make a variable show the result when a value is set.

From the help file.

The fact that it works without the '=' is a 'happy accident'.

I've seen cases where it most certainly doesn't work, and has caused the scripter much grief.

In any case, we're going off topic here ;P

Re: help with timers [Re: Bekar] #177379 24/05/07 09:15 AM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Originally Posted By: Bekar
From the help file.

The fact that it works without the '=' is a 'happy accident'.

I've seen cases where it most certainly doesn't work, and has caused the scripter much grief.

In any case, we're going off topic here ;P


I am aware of the help file... smirk

I've never had a problem with not using an equals sign. I would be interested in hearing about one of these cases where it most certainly doesn't work (perhaps in a private message if this is too off topic...)


NaquadaBomb
www.mirc-dll.com
Re: help with timers [Re: NaquadaServ] #177381 24/05/07 10:15 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
//var %a $str(a,%b)

It doesn't matter whether %b exists or not of course.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: help with timers [Re: qwerty] #177382 24/05/07 10:34 AM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Odd bug, it seems that %b is not evaluated, because this works...

Code:
alias vartest {
  var %b 10
  var %a $str(a, $eval(%b, 2))
  echo -s %a
}
;; OR
alias vartest {
  var %b 10
  var %a $str(a, [ %b ])
  echo -s %a
}


NaquadaBomb
www.mirc-dll.com
Re: help with timers [Re: NaquadaServ] #177384 24/05/07 10:50 AM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Not really a bug when you use invalid syntax smile

Also, the reasons for [ ] and $eval working are different. The [ ] brackets evaluate %b early whereas $eval just serves as 'padding' (for want of a better word). Something like $abs(%b) or $null %b would have the same effect (seperating the %var from the comma is the issue, IIRC).

Last edited by Collective; 24/05/07 10:55 AM.
Re: help with timers [Re: NaquadaServ] #177400 24/05/07 02:37 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
/var works without an = sign only when there isn't an identifier used. But once you start using identifiers, it will usually fail. For that reason alone, all scripters should *always* use an = sign to prevent running into unexpected problems caused by not using one. Besides, it's proper syntax and it's always better to follow proper syntax regardless what else works.


Invision Support
#Invision on irc.irchighway.net
Re: help with timers [Re: Riamus2] #177446 24/05/07 09:34 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
/var discussion continued here.

Sparta, sorry for hijacking your thread smile