|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
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,.) }
|
|
|
|
Joined: May 2007
Posts: 23
Ameglian cow
|
Ameglian cow
Joined: May 2007
Posts: 23 |
think you need to change the calc to multiply 5 by %c not 2 by $chan(0)
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.
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
Two things to note though.. First, 'var' should have an '=' if you assign it a value, i.e. 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:
var %c = $chan(0)
while (%c) {
<code>
dec %c
}
Anyway 
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
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.
var %c = 0, %cc = $chan(0)
while (%c < %cc) {
inc %c
;commands here
}
-genius_at_work
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 580 |
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.
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
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
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 580 |
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...  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...)
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 580 |
Odd bug, it seems that %b is not evaluated, because this works...
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
}
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
Not really a bug when you use invalid syntax  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.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
/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
|
|
|
|
Joined: Dec 2002
Posts: 503
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 503 |
/var discussion continued here. Sparta, sorry for hijacking your thread 
|
|
|
|
|