mIRC Home    About    Download    Register    News    Help

Print Thread
#176461 10/05/07 07:37 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I have a small problem with this code, anyone that can spot it? the problem is that when i loop true the file, then it do 'join %chan'. How ever it join the channel two times 'if the channels is +k and you dont have the key you see it', any idea on how to solve this?
Code:
alias test {
  var %x 0
  var %xx $lines(" $+ $mircdiraj\ $+ %tnwork $+ .txt $+ ")
  :loop
  var %chan = $read($mircdiraj\ $+ %tnwork $+ .txt,nt,%x)
  inc %x
  join %chan
  if (%x <= %xx) { goto loop }
  else {
    return
  }
}


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #176464 10/05/07 09:15 AM
Joined: Feb 2006
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
Personally I'd highly recommend against using goto loops, all programmers hate them as they only result in unreadable spaghetti code, code that can't be rapidly followed by a human, and are in the end slower than a legitamite type of loop due to, at least in most languages, how loops are compiled.

Although I don't see any obvious error's from here, I also have no clue what is in your text file. Generally, you can't join a channel twice, a second join attempt just focuses the window, is that what is happening?

Code:
alias test {
  set -l %xx $lines($+(",$mircdir,aj\,%tnwork,.txt,"))
  set -l %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
  while (%xx) {
    dec %xx
    set %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
    join %chan
  }
}


Also note that since you don't have timered joining, if you are on a network that mass joining channels counts as flooding, you could get the quit message "Killed (Excess Flood)" and as such, I'd recoment something like a timer loop or just a few dozen timers, depending on your preference.

Timers:
Code:
alias test {
  set -l %xx $lines($+(",$mircdir,aj\,%tnwork,.txt,"))
  set -l %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
  while (%xx) {
    dec %xx
    set %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
    .timer 1 $calc(2* %xx) join %chan
  }
}


Timer loop:
Code:
alias test {
  if (!$1) set -l %xx $lines($+(",$mircdir,aj\,%tnwork,.txt,"))
  else set -l %xx $1

  set -l %chan $read($+(",$mircdir,aj\,%tnwork,.txt,")),nt,%xx)

  join %chan | dec %xx
  if (%xx != 0) .timertest 1 2 test %xx
}



Note:: This joins channels from the end of the text file to the start, which for me doesn't matter since I have them auto-sorted. I also haven't tested either of these, but they look sound to me compared to the one I have for autojoin that is based on just a long variable list as accessing a file takes longer and my list of autojoin chans, all 44 of them, doesn't extend over the variable size limit.


Edit::
Here's what I use for auto-join if you're interested. I just set all chans I want to join for the one network where I join the most chans to a variable, then call this alias on startup. This also allows for you to switch to rapid-join if you oper up midway into the joining process (since opers can't Excess Flood).
Code:
alias all {
  if ($1 isnum) set -l %n $1 | else set -elu10 %n 0 | set -elu10 %time 3
  if (o isincs $usermode) set %time 0
  inc %n
  if (%n <= $numtok(%chans.sort,32)) { .timerall 1 %time all %n | j -n $gettok(%chans.sort,%n,32) }
}

Last edited by Midori; 10/05/07 09:40 AM.

/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
sparta #176467 10/05/07 10:33 AM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
Yuck, a goto loop sick

I also can't see exactly why your code would be a having problems, although changing this might help.

Code:
  ; placing an echo line here might help debug this???
  echo -s Read from file: %chan
  ; Change this line
  join %chan
  ; to...
  if (!$chan(%chan)) join %chan

Also, you can completely remove this code. Logically this behaviour is implied. Since you are using goto prior, the else isn't needed, and since you are not returning an actual value, return is not needed. Just trying to save you a few lines of code... smile

Code:
  else {
    return
  }

Edit: If this is being done after connecting, mIRC might be trying to auto join the channel at the same time, check your Channels List.

Last edited by NaquadaServ; 10/05/07 10:36 AM.

NaquadaBomb
www.mirc-dll.com
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
As i wrote befor i know it joins the channel 2 times, if the channel is keyed "+k", then i got the message:

#channel unable to join channel (need correct key)

and if it comes 2 times, then the script trying to join, and using the echo "as i did befor i posted here", then i got %chan echo'ed to me 2 times, and the problem must be here "if (%x <= %xx) { goto loop }", it looking if %x is lower value then %xx , and i only guess that it check if it's lower, and if it's not, then it do one extra loop and that cosing the problem, i also tested == instead of <=, same problem there. so dunno how to fix it.. and thnx for the answers, i will look at the codes pasted here and try to understand what everything does.. smile


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Midori #176486 10/05/07 02:35 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I tested your code, it dosent work as it should, this one:
Code:
alias test {
  set -l %xx $lines($+(",$mircdir,aj\,%tnwork,.txt,"))
  set -l %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
  while (%xx) {
    dec %xx
    set %chan $read($+(",$mircdir,aj\,%tnwork,.txt,"),nt,%xx)
    join %chan
  }
}

it only join the last channel in the *.txt file, not the others added in it..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #176497 10/05/07 06:26 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
alias test {
  var %x = 1, %xx = $lines(" $+ $mircdiraj\ $+ %tnwork $+ .txt $+ ")
  while %x <= %xx {
    var %chan = $read($mircdiraj\ $+ %tnwork $+ .txt,nt,%x)
    .timer 1 %x join %chan
    inc %x
  }
}


This still won't work properly for channels that require a key.
In order to make that modification, I'm going to need to know where and how the key is stored, or if you prefer to enter the key manually each time.

Note: I'm not positive that I can do it so that you enter the key each time, and I don't have time at the moment to research it further.

Last edited by RusselB; 10/05/07 06:30 PM.
sparta #176501 10/05/07 08:23 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias test { filter -fk $qt(aj\,%tnwork,.txt) _test }
alias _test { join $1 }


As long as you store one channel (and key if you like) per each line in the file, this should work fine.

RusselB #176564 11/05/07 04:09 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
everything is stored in a *txt as plain text, that means i only need to grab the channel, then the key behind the channel.. so you dosent need to do anything wink i fixed the code that i had problem with, was missing a %var, adding that and everything worked ok smile


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }

Link Copied to Clipboard