|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Looking for a better way to do this, if one exists. if $did(3).state || $did(4).state || $did(5).state || $did(6).state || $did(7).state || $did(8).state || $did(9).state || $did(10).state {
if !$didwm($dname,2,$did(2,0)) {
did -a $dname 2 $did(2,0)
}
|
|
|
|
Joined: Jul 2006
Posts: 4,185
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,185 |
Not really better but shorter and maybe faster even if I'm sure you don't care about speed... : if (0 isin $regsubex(xxxxxxxx,/x/g,$iif($did($calc(2 + \n)).state,0,1))) {
if !$didwm($dname,2,$did(2,0)) {
did -a $dname 2 $did(2,0)
}
} Not tested of course, but should work
Last edited by Wims; 11/03/09 12:37 AM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
I appreciate the suggestion, but am having a hard time understanding the code. Would you be kind enough to explain it?
|
|
|
|
Joined: Jul 2006
Posts: 4,185
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,185 |
Sorry $regsubex is used to make a "while" with 8 iteration (input string is 8 'x', and we're matching all of them using /g). When replacing each 'x', just check for $did($calc(\n + 2)).state (\n represent the match number) in order to have number from 3 to 10, if state is 1, replace with 0, else with 1. Then use isin to check if there is a 0 in the result of $regsubex, if so, it mean that at least one your condition is true. Hope this help Edit : in fact the //g parameter was missing. Edit2 : $regsubex is generally faster than a while, but here, it will test all your $did().state even if previous are 1, whereas an if statement won't do this, so really, I don't know if this code is better.
Last edited by Wims; 11/03/09 12:42 AM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
I don't think there is a 'better' way to accomplish what you are doing there. There are ways that aren't as wide, or can be altered more easily (or dynamically).
[code]
var %a = 3 4 6 8 10 42
;
var %x = 0, %i = 0, %ii = $numtok(%a,32)
while (%a < %aa) {
inc %a
if ($did($gettok(%a,%i,32)).state == 1) {
%x = 1
break
}
}
if ((!$didwm($dname,2,$did(2,0))) && (%x)) {
did -a $dname 2 $did(2,0)
}
(untested) You can change the contents of %a in another part of your script so that different conditions (checkboxes) can affect the results of the script dynamically. -genius_at_work
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
You mixed up the names of your variables there - you should be checking and incrementing %i and %ii.
RusselB: As far as making it better there really isn't any good way in mIRC scripting. Either use the static method you've currently got or use a loop like genius_at_work's to make it simpler to alter later. Wims' is smaller and may be faster but it's highly unreadable and speed is irrelevant in that code in any case.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Thanks for the replies and alternative suggestions. All things considered, I think I'll stick with what I already have.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
Just for fun, you could shave a few more bytes off: if ($regsubex(........,/./g,$xor($did($calc(2+ \n)).state,0))) && (!$didwm($dname,2,$did(2,0))) did -a $dname 2 $did(2,0)
|
|
|
|
Joined: Jul 2006
Posts: 4,185
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,185 |
He he, it wasn't the purpose
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Feb 2006
Posts: 546
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 546 |
you don't need $xor() there, xor-ing with 0 doesn't change a number :P
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
You are right!
I got confused with shortening the $iif($did().state,0,1) backwards approach that wims used :P
|
|
|
|
Joined: Jul 2006
Posts: 4,185
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,185 |
Lol, indeed, the $iif isn't needed.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|