mIRC Home    About    Download    Register    News    Help

Print Thread
#89668 08/07/04 08:27 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
According to the mIRC help file, it says while loops can be embedded. Every time I embed a while loop inside another, it turns into an endless loop. Could someone please post an example of an embedded while loop?


To be more specific, I am using a while loop to see find out the socket names of the open sockets. I need to use another while loop to see if each socket that the $sock() while loop returns is listed in a @window by while looping the $lines() identifier.

#89669 08/07/04 08:38 PM
Joined: Mar 2004
Posts: 130
T
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
you dont need to loop to see how many sockets are open

just type //echo -s $sock(*,0) to get the total numbers of open socktes

#89670 08/07/04 08:39 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
I meant the socket names.

#89671 08/07/04 08:46 PM
Joined: Mar 2004
Posts: 130
T
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
If you talking about more then 50.000 open sockets it is a littel bit hard smile

#89672 08/07/04 08:53 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
Let me rephrase my question.


What I am trying to do is while loop the $sock() identifier in order to return the socket names of the open sockets.

This is very simple:

Code:
alias socks {
var %i = 1
while ($sock(*,%i)) {
echo -a $ifmatch
inc %i
}
}


Now, I have an @window that has every socket name of each open socket listed. I need to somehow check to see if the socket name of each socket the "socks" command returned is indeed listed inside the @window. If it is not listed, then my script will add it to the @window.

Code:
alias sockwindow {
var %w = 1
while ($line(@Socks,%w)) {
echo -a $gettok($ifmatch,2,32)
inc %w
}
}


The above command would list the names of the sockets that are listed in my @window. So, what I want to do is a comparison to see if the data the "socks" command returned matches the data the "sockwindow" command returned. I am guessing I need two while loops to do this.

#89673 08/07/04 08:57 PM
Joined: Mar 2004
Posts: 130
T
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
Code:
 
skloop {
  var %x = 1
  :salive
  if ($window(@yourwin)) { aline @yourwin %x $sock(*,%x).name }
  inc %x
  if (%x < $sock(*,0)) goto salive
}


 

#89674 08/07/04 09:05 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Hope this helps with understanding nested loops:

Code:
alias socks {
  ; intiialize the outer while loop variable
  [color:#008000]var[/color] [color:green]%i[/color] [color:#008000]= 1[/color]
  ; loop through a list of open sockets
  [color:#008000]while ($sock(*,[/color][color:green]%i[/color][color:#008000])) {[/color]
    ; set it as a name that's easy to recall
    [color:#008000]var %sname = $v1[/color]

    ; set the [color:Red]nested[/color] while loops variable for the line
    ; also set the name of the window you are searching in
    [color:#396EA5]var[/color] [color:blue]%j[/color] [color:#396EA5]= 1, %window = @custom[/color]
    ; loop through each line of the @window
    [color:#396EA5]while ($line(%window,[/color][color:blue]%j[/color][color:#396EA5])) {[/color]
      ; check if the socket is listed in the window
      [color:#396EA5]if (%sname == $v1) /echo -s Found a socket listed in %window - %sname[/color]

      ; increase loop variable
      [color:#396EA5]/inc[/color] [color:blue]%j[/color]
    [color:#396EA5]}[/color]

    ; increase loop variable
    [color:#008000]/inc[/color] [color:green]%i[/color]
  [color:#008000]}[/color]
}


-KingTomato
#89675 08/07/04 09:13 PM
Joined: Mar 2004
Posts: 130
T
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
Sory when i am asking but why looping first true all sockets

and then looping true the window to see if a socket exist in a window , why not when socket found adding to window direct

#89676 08/07/04 09:20 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
Thanks very much KingTomato! That's exactly what I wanted! laugh

#89677 08/07/04 09:40 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
By the way the nested while loop is unnecessary, you could just use:
Code:
var %i = 1
while ($sock(*, %i)) {
  if ($fline(@custom, $v1)) echo -s Found a socket listed in @custom - $v1
  inc %i
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#89678 08/07/04 09:44 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
I don't really get what you're asking for, but if you just want to check if a socket is already listed before adding it to the window, there's no need, aline -n will check for you.

Code:
alias socks {
  var %i = 1
  while ($sock(*,%i)) {
    aline -n @win $ifmatch
    inc %i
  }
}


New username: hixxy
#89679 08/07/04 09:49 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
That works well too. Plus, it's small. Thanks.


Link Copied to Clipboard