mIRC Homepage
Posted By: sparta help with timers - 23/05/07 10:12 AM
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..
Posted By: chiram Re: help with timers - 23/05/07 10:58 AM
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
Posted By: Bekar Re: help with timers - 23/05/07 11:45 AM
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
Posted By: genius_at_work Re: help with timers - 23/05/07 02:06 PM
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
Posted By: NaquadaServ Re: help with timers - 24/05/07 08:55 AM
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.
Posted By: Bekar Re: help with timers - 24/05/07 09:03 AM
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
Posted By: NaquadaServ Re: help with timers - 24/05/07 09:15 AM
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...)
Posted By: qwerty Re: help with timers - 24/05/07 10:15 AM
//var %a $str(a,%b)

It doesn't matter whether %b exists or not of course.
Posted By: NaquadaServ Re: help with timers - 24/05/07 10:34 AM
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
}
Posted By: Collective Re: help with timers - 24/05/07 10:50 AM
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).
Posted By: Riamus2 Re: help with timers - 24/05/07 02:37 PM
/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.
Posted By: Bekar Re: help with timers - 24/05/07 09:34 PM
/var discussion continued here.

Sparta, sorry for hijacking your thread smile
© mIRC Discussion Forums