mIRC Homepage

is there a better way to do this?

Posted By: ghettowboy

is there a better way to do this? - 04/11/06 10:01 PM

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
Posted By: Kurdish_Assass1n

Re: is there a better way to do this? - 04/11/06 10:37 PM

use while:
Code:
while (%var < %var1) { do these commands } 

if that's what you're looking for.
Posted By: RusselB

Re: is there a better way to do this? - 05/11/06 01:34 AM

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
  }
}
 
Posted By: ghettowboy

Re: is there a better way to do this? - 05/11/06 04:15 PM

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?
Posted By: KingTomato

Re: is there a better way to do this? - 05/11/06 04:31 PM

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
  }
Posted By: ghettowboy

Re: is there a better way to do this? - 05/11/06 05:03 PM

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..
Posted By: KingTomato

Re: is there a better way to do this? - 05/11/06 05:56 PM

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.
Posted By: ghettowboy

Re: is there a better way to do this? - 05/11/06 06:15 PM

thats was it...... missed that myself....... thank you very much

thanks to all who replied.. smile
Posted By: qwerty

Re: is there a better way to do this? - 05/11/06 06:34 PM

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.
Posted By: KingTomato

Re: is there a better way to do this? - 05/11/06 07:17 PM

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.
Posted By: DaveC

Re: is there a better way to do this? - 05/11/06 07:17 PM

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.
Posted By: ghettowboy

Re: is there a better way to do this? - 06/11/06 02:59 AM

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?
Posted By: DaveC

Re: is there a better way to do this? - 06/11/06 06:12 AM

Add this alias
alias noop { }
Posted By: ghettowboy

Re: is there a better way to do this? - 06/11/06 12:29 PM

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
Posted By: ghettowboy

Re: is there a better way to do this? - 06/11/06 12:51 PM

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
Posted By: qwerty

Re: is there a better way to do this? - 06/11/06 01:08 PM

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-)
Posted By: ghettowboy

Re: is there a better way to do this? - 06/11/06 01:51 PM

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???
© 2022 mIRC Discussion Forums