mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
hello all,

this code is working good.. it's not my own but, works for my purposes... but instead of the goto loops, is there a way to make this code less bulkie? perhaps by using while loop(s)?

if so how would that work for this instance???

here's the code i'm inquiring on:
Code:
if (%found != $null) { 
        %i = 0
        :loop1
        inc %i | inc %all
        if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. | halt }
        if ($findfile($r.srv(Fserve.1,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.1,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) - $len($r.srv(Fserve.1,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) $+  $+ $C(1) $+ ) trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.1,Trigger) $+  $+ $C(1) $+ )   }
        if (%i < %found) { goto loop1 }
        goto next
      }
      :next
      if (%found.2 != $null) { 
        %i = 0
        :loop2 
        inc %i | inc %all
        if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. | halt }
        if ($findfile($r.srv(Fserve.2,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.2,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.2,Root.Dir),%search,%i)) - $len($r.srv(Fserve.2,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.2,Root.Dir),%search,%i)) $+  4+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.2,Trigger) $+  $+ $C(1) $+ ) }
        if (%i < %found.2) { goto loop2 }

        goto next2
      }
      :next2
      if (%found.3 != $null) { 
        %i = 0
        :loop3 
        inc %i | inc %all
        if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. | halt }
        if ($findfile($r.srv(Fserve.3,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.3,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.3,Root.Dir),%search,%i)) - $len($r.srv(Fserve.3,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.3,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.3,Trigger) $+  $+ $C(1) $+ ) }
        if (%i < %found.3) { goto loop3 }
        goto next3
      }
      :next3
      if (%found.4 != $null) { 
        %i = 0
        :loop4 
        inc %i | inc %all
        if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1) too many search results to display. | halt }
        if ($findfile($r.srv(Fserve.4,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.4,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.4,Root.Dir),search,%i)) - $len($r.srv(Fserve.4,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.4,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.4,Trigger) $+  $+ $C(1) $+ ) }
        if (%i < %found.4) { goto loop4 }
        goto next4
      }
      :next4
      if (%found.5 != $null) { 
        %i = 0
        :loop5 
        inc %i | inc %all
        if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. | halt }
        if ($findfile($r.srv(Fserve.5,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.5,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.5,Root.Dir),%search,%i)) - $len($r.srv(Fserve.5,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.5,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:(  $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.5,Trigger) $+  $+ $C(1) $+ ) }
        if (%i < %found.5) { goto loop5 }
        goto end
      }
    }
    :end
  }

  


this is only part of the script but for what i'm asking i think this should do..

thanks to you all in advance.. grin

Joined: Apr 2006
Posts: 400
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Apr 2006
Posts: 400
use while:
Code:
while (%var < %var1) { do these commands } 

if that's what you're looking for.


-Kurdish_Assass1n
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Here's a re-write using while loops. I'd also like to suggest that you see if there's a way to make those messages shorter, as the length of them might cause problems.
Code:
 if (%found) { 
  %i = 1
  while %i <= %found {
    if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. }
    elseif ($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)  {
    inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.1,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) - $len($r.srv(Fserve.1,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) $+  $+ $C(1) $+ ) trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.1,Trigger) $+  $+ $C(1) $+ )   }
    inc %i | inc %all
  }
}
if (%found.2) { 
  %i = 1
  while %i <= %found.2 {
    if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. }
    elseif ($findfile($r.srv(Fserve.2,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.2,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.2,Root.Dir),%search,%i)) - $len($r.srv(Fserve.2,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.2,Root.Dir),%search,%i)) $+  4+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.2,Trigger) $+  $+ $C(1) $+ ) }
  }
}
if (%found.3) { 
  %i = 1
  while (%i < %found.3) { 
    if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. }
    elseif ($findfile($r.srv(Fserve.3,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.3,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.3,Root.Dir),%search,%i)) - $len($r.srv(Fserve.3,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.3,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.3,Trigger) $+  $+ $C(1) $+ ) }
    inc %i | inc %all
  }
}
if (%found.4) { 
  %i = 1
  while (%i < %found.4) { 
    if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1) too many search results to display. | halt }
    if ($findfile($r.srv(Fserve.4,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.4,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.4,Root.Dir),search,%i)) - $len($r.srv(Fserve.4,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.4,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.4,Trigger) $+  $+ $C(1) $+ ) }
    inc %i | inc %all
  }
}
if (%found.5) { 
  %i = 1
  while (%i < %found.5) { 
    if (%all == 6) { .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display. | halt }
    if ($findfile($r.srv(Fserve.5,Root.Dir),%search,%i) != $null) { inc %current | .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.5,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.5,Root.Dir),%search,%i)) - $len($r.srv(Fserve.5,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.5,Root.Dir),%search,%i)) $+  $+ $C(1) $+ )  trigger:(  $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.5,Trigger) $+  $+ $C(1) $+ ) }
    inc %i | inc %all
  }
}
 

Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
thank you both for your replies... thats more or less what i was thinking along the lines of...

that rewrite tho RusselB, really doesn't seem to work at all.. there were a couple descrepencies in the code you provided.. a couple missed brackets an such..i think they are anyways.. so i corrected them accordingly... still not working..
any further thoughts?

Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
untested but this should solve the problem.

Code:
  var %f = 1, %i = 1, %all = 0
  while (%found [ $+ [ $iif(%f > 1,$+(.,%f)) ] ] != $null && %f < 6) {
  
    %i = 1
    while (%i < %found [ $+ [ $iif(%f > 1,$+(.,%f)) ] ]) {
      /inc %all
      
      if (%all == 6) {
        .msg $nick $C(1) $+ ( $+ $C(2) $+ overflow $+ $C(1) $+ ) $+ $C(1)  too many search results to display.
        return
      }
      else if ($findfile($r.srv(Fserve.1,Root.Dir),%search,%i) != $null) {
        /inc %current
        .msg $nick $C(1) $+ ( $+ $C(2) $+  $+ %current $+  $+ $C(1) $+ ) file:( $+ $C(2) $+ $right($findfile($r.srv(Fserve.1,Root.Dir),%search,%i),$calc($len($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) - $len($r.srv(Fserve.1,Root.Dir)))) $+ $C(1) $+ )  size:( $+ $C(2) $+  $+ $big($findfile($r.srv(Fserve.1,Root.Dir),%search,%i)) $+  $+ $C(1) $+ ) trigger:( $+ $C(2) $+  $+ /ctcp $+ $chr(32) $+ $r.srv(Fserve.1,Trigger) $+  $+ $C(1) $+ )
      }
      
      /inc %i
    }
      
    /inc %f
  }

Last edited by KingTomato; 05/11/06 04:32 PM.

-KingTomato
Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
thanks KingTomato ,

that working better smile.... am getting results now. but however its not looping thru to list all the results within the limit.. only showing one result..??

sorry if i'm being a bother..

Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
I'm sorry, try changing this line:

while (%i < %found [ $+ [ $iif(%f > 1,$+(.,%f)) ] ]) {

to this:

while (%i <= %found [ $+ [ $iif(%f > 1,$+(.,%f)) ] ]) {

I retyped the line, that's why. Missed a comparison.


-KingTomato
Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
thats was it...... missed that myself....... thank you very much

thanks to all who replied.. smile

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This has been beaten to death on these forums but many scripters keep doing it: using $findfile() like this is extremely wasteful (= slow), as this post explains.

Last edited by qwerty; 06/11/06 12:54 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
I wasn't going for efficiency, just condesation. I realize this is a poor use of $findfile but it's also not my bot. But I do appreciate the input.


-KingTomato
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I agree, and Its an absolute killer across network drives.
But thats the fileservers owners rblem they can always turn cached indexes on :-) (opps fileserver talk)
The identifiers have been changed but the format of the parameters etx looks alot like invision.

Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
not invision dave but anywho.......

okay how would i go about this without the use of noop ? cause the script is using 6.12 and is being used by quite a few ppl so trying to get them to upgrade would be a royal rear kicker.... but as was mentioned ... that would be my problem.. :tongue:

anyone have good thoughts on this?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Add this alias
alias noop { }

Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
thats it dave??? i mean thats so simple i feel dumb.. lol anyways, i had no idea thats ALLl noop is..... i'll give it a try i guess...

thanks

Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
i appreciate the fact you've pointed out some misuse of code in the script... and so generously provided a link that explains why that is... and with davec's help i've learned what /noop actually does.. lol.... but i fail to see other than that, the connection between the two posts.... unless that was it...

in that case all i have to say is THANKS! smirk

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
My link was meant to take you to hixxy's reply but somehow I omitted the anchor so it linked to the first post of the thread, sorry about that. And yes, the connection was just $findfile(): hixxy explains why using it in a while loop is bad and how you can avoid that, by using $findfile()'s internal looping feature. For example, this:
Code:
while (%i &lt; %total) {
  someCommand $findfile(c:\,*,%i)
  inc %i
}

is much slower than this:
Code:
noop $findfile(c:\,*,0,someCommand $1-)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Oct 2006
Posts: 20
G
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Oct 2006
Posts: 20
okay,

and with that noop alias dave gave.. lol.. that will work the same way?


***EDIT
looking back at the original code ..... would it be better just to leave it as is then???

Last edited by ghettowboy; 06/11/06 02:06 PM.

Link Copied to Clipboard