|
Joined: Jul 2003
Posts: 27
Ameglian cow
|
OP
Ameglian cow
Joined: Jul 2003
Posts: 27 |
im using a @win for my channel and just have a question in regards to a while loop...the loop works fine listing ops,halfops,voices,etc. but the trouble im having is that if a nick is both a OP and VOICE itll list that nick twice..as a OP and as a VOICE..just wanna know if there is any way around that while listing them?
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
Why you didn't just ask me this in my room I don't know.. lol... Anyway, just use 'goto':
while ($nick($chan,%i)) {
if ($nick($chan,%i) isop $chan) { do things here | goto end }
if ($nick($chan,%i) isvo $chan) { do things here | goto end }
:end
inc %i
}
- Jason
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
and what's wrong with else if?
while ($nick($chan,%i)) {
if ($nick($chan,%i) isop $chan) { do things here | goto end }
if ($nick($chan,%i) isvo $chan) { do things here | goto end }
:end
inc %i
}
or
while ($nick($chan,%i)) {
if ($nick($chan,%i) isop $chan) { do things here }
else if ($nick($chan,%i) isvo $chan) { do things here }
inc %i
}
Personally, the latter looks much more neat.
-KingTomato
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
Because as stated in the original post, if a user has been op'd and voiced, it will trigger twice because both if statements return $true.
if ($nick isop $chan) { } ;this will return true because they're an op if ($nick isvo $chan) { } ;this will return true because they were voiced either before or after being op'd
- Jason
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
your telling it to goto end anywas after the if..
if (blah) { stuff | goto end } if (blah) { stuff | goto end } :end
if much diff from
if (blah) { stuff } if (blah) { stuff }
-KingTomato
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
The reason I told him to do it like that is because I've seen the result he's getting doing it the other way. For some reason in the custom window he's made for channels, it returns both the + and @ with $nick($chan,$nick).pnick. It's doing the same thing when he's listing the nicknames, causing the one nickname to appear twice in the nicklist, once with an @ and once with a +.
He was using the: if (blah) {} | elseif (blah) {} format to begin with which is why I told him to bypass the second if with the goto command.
- Jason
|
|
|
|
Joined: Jul 2003
Posts: 27
Ameglian cow
|
OP
Ameglian cow
Joined: Jul 2003
Posts: 27 |
Thanks bro...yea your code works fine...it was listing me even tho i was a op and voice as both modes in the @window list...works fine now =)
|
|
|
|
Joined: Dec 2002
Posts: 117
Vogon poet
|
Vogon poet
Joined: Dec 2002
Posts: 117 |
That is why he added the else, so if ($nick isvo $chan) { blah } will only be executed if the user is not opped.
$input(Me like stars, You too?)
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
Ok, I understand that using the else that way will work for two statements. But, here's the other problem, he has the event listing nicknames in order, for example:
if (isop) { }
if (ishop) { }
if (isvo) { }
else { }
Where the else will only trigger if the user has no status at all. So, using the else anytime before that will cause problems unless you used something like:
if (isop) { }
else {
if (ishop) { }
else {
if (isvo) { }
else { }
}
}
Which is very messy. Now, the reason I was using the goto command is because with a custom window, both the $nick().pnick and isop, ishop, isvo operators return each and every one of the users status' (@, %, +), why? I don't know. But it does. So in order to not get the nickname listed in the nicklist twice as both an operator and a voiced user, or halfop and voiced user, whatever combination you can think of. The 'goto end' command will bypass all of the if-else statements, increase the %i variable and start again.
- Jason
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
if (isop) { } elseif (ishop) { } elseif (isvo) { } else { }
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
That's the exact same thing as using: if (isop) {} if (ishop) {} if (isvo) {} else {}
- Jason
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
No it isn't. Elseif means only do something if the previous if was false.
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
alias test1 {
if ($1 == blah) { echo -a $1 }
if ($1 == blah { echo -a $1 }
}
alias test2 {
if ($1 == blah) { echo -a $1 }
elseif ($1 == blah { echo -a $1 }
}
Both of these aliases will return "elseif" errors for the second if statement when you use /test1 blah or /test2 blah
- Jason
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
The first one gives "/if: invalid format", the seconds gives "/elseif: invalid format". That's because you missed a ).
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
I did that purposely to show you that it doesn't matter whether you use if or elseif, the second statement is automatically classed as an 'elseif' statement.
- Jason
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
Argh you're a complete plonker, that is a bug with mIRC's errors, it happened when I was testing something else too, I'll find the source of it later. alias test1 {
if ($1 == hello) { echo -a if1 triggered }
if ($2 == byebye) { echo -a if2 triggered }
}
alias test2 {
if ($1 == hello) { echo -a if1 triggered }
elseif ($2 == byebye) { echo -a elseif1 triggered }
} /test1 hello byebye/test1 blah byebye /test2 hello byebye /test2 blah byebye
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
I gave up reasoning with him a while ago, you should too. Some people remain stubborn.
-KingTomato
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
alias elseif.test {
var %count = 0
if 1 == 1 { inc %count }
if 1 == 1 { inc %count }
if 1 == 1 { inc %count }
if 1 == 1 { inc %count }
if 1 == 1 { inc %count }
echo -a * If: %count
%count = 0
if 1 == 1 { inc %count }
elseif 1 == 1 { inc %count }
elseif 1 == 1 { inc %count }
elseif 1 == 1 { inc %count }
elseif 1 == 1 { inc %count }
elseif 1 == 1 { inc %count }
echo -a * ElseIf: %count
} /elseif.test* If: 5 * ElseIf: 1 They are not at all the same thing. In the IF section, each IF is evaluated every single time, incrementing %count every time. In the ElseIf section, since the first IF condition is true, the 1 inc %count command is executed and then control drops out of the if-elseif-else control structure.
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
|
|
|
|
|