mIRC Home    About    Download    Register    News    Help

Print Thread
#213647 04/07/09 04:06 PM
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Hello,

I create this alias but when i used only one nick removes from the %AJM_nicks list why? i saw that did not make a loop :S any help?

Code:
alias ajm_check {
  if (!%AJM_nicks) { halt }
  ; %AJM_nicks westor,westor1,westor2,westor3,westor4,westor5,westor6,westor7,westor8
  var %i = 1
  while (%i <= $numtok(%AJM_nicks,44)) {
    var %ch = $gettok(%AJM_nicks,%i,44)
    if ((!%AJM_ [ $+ [ %ch ] $+ ] _message) && ($istok(%AJM_nicks,%ch,44))) { set %AJM_nicks $remtok(%AJM_nicks,%ch,44) | echo -s Successfully removed %ch nick }
    inc %i
  }
  inc %i
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
westor #213650 04/07/09 04:42 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
1) The line where the variable %AJM_nicks is set has a ; in front of it, which, in mIRC scripting terms means that the line is a remark, and is not to be processed.

2) The condition
Code:
($istok(%AJM_nicks,%ch,44)
is irrelevant, as you are creating the %ch variable from the %AJM_nicks variable, in the line immediately proceeding that line.

3)
Code:
$remtok(%AJM_nicks,%ch,44)
is missing the parameter to tell mIRC which occurrence of %ch is to be removed from %AJM_nicks. See /help $remtok

4) By removing %ch from %AJM_nicks, then increasing the %i variable, going from the original variable, the nicks removed would be the 1st, 3rd, 6th, 10th, etc.

5) You have an additional inc %i in your code, which would execute after the loop has finished.

RusselB #213653 04/07/09 04:54 PM
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
the ; i gave you to see what i have into my variables setted that line is not in the alias , any way can you help me with giving me an correct example ?


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
RusselB #213655 04/07/09 05:21 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
$remtok(%AJM_nicks,%ch,44) is fine, by defaut the first "occurence" is removed


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #213656 04/07/09 05:26 PM
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Originally Posted By: Wims
$remtok(%AJM_nicks,%ch,44) is fine, by defaut the first "occurence" is removed


what do you mean with this , give an example!


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
westor #213657 04/07/09 06:24 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If you remove a token, you mustn't increase the numer in your loop.
Code:
alias example {
  var %example = 1 2 3 4 5 6
  var %n = 1
  while ($gettok(%example,%n,32)) {
    if ($v1 isnum) { var %example = $deltok(%example,%n,32) } 
    inc %n
  } 
  echo -a tokens remaining: %example
}
Will remove all the tokens, because they are all numbers, right?
Nope. If you delete a token and increase the number, the script "skips" some tokens: Token number one is deleted, and the token "2" is now token number one. If you inc %n to 2, the script continues with token number two - which is: "3"!
If it shall check every token: use "else inc %n"
Alternatively:
- use a decreasing loop if your script may delete the Nth token
- don't change the variable during the loop. Instead (for example) add the tokens you want to keep to a separate variable; and use the new variable, or replace the original variable with the data of the new variable after your loop has finished.

westor #213658 04/07/09 06:55 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
For example:
Code:
alias ajm_check {
  var %AJM_nicks = westor,westor1,westor2,westor3,westor4,westor5,westor6,westor7,westor8
  var %ch = $numtok(%AJM_nicks,44)
  while (%ch) {
    set %AJM_nicks $remtok(%AJM_nicks,$gettok(%AJM_nicks,%ch,44),44))
    echo -s %AJM_nicks removed.
    dec %ch
  }
}
The echo isn't needed but just to show you how all the tokens are removed one after another.

westor #213659 04/07/09 06:56 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Why wait for an exemple when you can just testing this by yourself with one second ?

Anyway, the help give this syntax :
$remtok(text,token,N,C)
N can be omitted, $remtok(text,token,1,C) is the same as $remtok(text,token,C) and this works for most token identifiers if not all


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard