mIRC Homepage
Posted By: bwr30060 Problem with alias - 17/01/06 12:05 AM
Hi,

I've added aliases to my nick tracker script, but I'm having problems with them. The alias called fixfile is supposed to scan each token of a line of nicks and times and remove the tokens that didn't get written with both nick and time, but it doesn't do that. I'll have to post the whole script so you can see what my variables are. Thanks for any help.
Code:
on 1:JOIN:#: {
  set %addlength. [ $+ [ $nick ] ] $len($wildsite)
  set -u5 %owner.chan $chan 
  set %join.address. [ $+ [ $nick ] ] $wildsite
  set %join.precompaddress. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *)
  set %oldaddress $readn
  set %join.compaddress. [ $+ [ $nick ] ] $left(%join.precompaddress. [ $+ [ $nick ] ],%addlength. [ $+ [ $nick ] ])
  set %join.compnick. [ $+ [ $nick ] ] $read(C:\mirc\nicks.txt,w,$nick $+ *)
  set %oldnick $readn
  set %join.time. [ $+ [ $nick ] ] $mid($ctime,2,8)
  set %join.newnick $chr(44) $+ $nick %join.time
  set %join.bothnew $wildsite $+ $chr(44) $+ $nick  %join.time. [ $+ [ $nick ] ]
  if (whatever1* iswm $nick) { 
    if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { 
      echo 4 -s address match $nick
      $newecho($nick,%join.precompaddress. [ $+ [ $nick ] ]) 
    }
    else { echo 4 -s No Match $nick }
  }
  elseif (whatever2* iswm $nick) { 
    if (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { 
      $newecho($nick,%join.precompaddress. [ $+ [ $nick ] ]) 
      echo 4 -s address match $nick
    }
    else { echo 4 -s No Match $nick }
  }
  elseif (%join.address. [ $+ [ $nick ] ] == %join.compaddress. [ $+ [ $nick ] ]) { 
    echo 4 -s address match $nick
    $newecho($nick,%join.precompaddress. [ $+ [ $nick ] ]) 
    goto NickEval 
  }
  else { 
    write C:\mirc\nicks.txt %join.bothnew 
    echo 4 -s $nick is a new entry 
  }
  halt
  :NickEval
  if ($nick = %join.compnick. [ $+ [ $nick ] ]) { 
    $newecho($nick,%join.precompaddress. [ $+ [ $nick ] ]) 
    var %templine = $read(C:\mirc\nicks.txt,w,$wildsite $+ *)
     [color:red]  [/color] ;I just changed passline to equal $wildsite 
   [color:red]  [/color] var %passline = $wildsite
    echo -a passline is %passline join.newnick is %join.newnick
    $fixfile(%passline,%join.newnick)  
  }
  else { 
    var %templine = $read(C:\mirc\nicks.txt,s,$wildsite $+ *)
     [color:red]  [/color] var %passline = $wildsite
    $fixfile(%passline,%join.newnick) 
  }
}
on 1:NICK: {
  set %addlength. [ $+ [ $newnick ] ] $len($wildsite)
  set %nick.address. [ $+ [ $newnick ] ] $wildsite
  set %nick.precompaddress. [ $+ [ $newnick ] ] $read(C:\mirc\nicks.txt,w,$wildsite $+ *)
  set %oldaddress $readn 
  set %nick.compaddress. [ $+ [ $newnick ] ] $left(%nick.precompaddress. [ $+ [ $newnick ] ],%addlength. [ $+ [ $newnick ] ])
  set %nick.compnewnick $read(C:\mirc\nicks.txt,w,$newnick $+ *) 
  set %oldnick $readn
  set %nick.newnick $newnick %nick.nicktime 
  set %nick.nicktime $mid($ctime,2,8)
  set %nick.bothnew $wildsite $+ $chr(44) $+ $newnick %nick.nicktime 
  set %nick.newnicktime $newnick %nick.nicktime
  if ($newnick == $me) { echo }
  elseif ($newnick == %nick.compnewnick) { 
    echo -s nick match
    $newecho($newnick,%nick.precompaddress. [ $+ [ $newnick ] ]) 
  }
  elseif (%nick.address. [ $+ [ $newnick ] ] == %nick.compaddress. [ $+ [ $newnick ] ]) { 
    echo -s address match 
    var %templine = $read(C:\mirc\nicks.txt,w,$wildsite $+ *)
     [color:red]  [/color] var %passline = $wildsite
    $fixfile(%passline,%nick.newnicktime)
    $newecho($newnick,%nick.precompaddress. [ $+ [ $newnick ] ]) 
  }
  else { 
    write C:\mirc\nicks.txt %nick.bothnew
    echo 4 -s $newnick is a new entry 
  }
}
on 1:QUIT: {
  unset % $+ *. $+ $nick
}
on 1:PART: {
  unset % $+ *. $+ $nick
  if (% $+ *. $+ $newnick) { unset % $+ *. $+ $newnick }
}
alias newecho {  
  var %list = $2
  var %line, %i = 2, %m = $numtok(%list,44)
  while (%i <= %m) {
    var %name = 3 $gettok($gettok(%list,%i,44),1,32)
    var %numdate = $gettok($gettok(%list,%i,44),2,32)
    var %newnumdate = 1 $+ %numdate $+ 0
    var %newdate = 2 $asctime(%newnumdate, ddd mmm d yyyy h:nn TT)
    var %line = %line $+ %name 2 %newdate $+ $chr(44)
    inc %i
  }  
  var %line = $gettok(4 $1 was %line,1-,44)
  echo -a %line 
}
alias fixfile {
  var %entry = $1
  var %newstuff = $2
  var %linenum = $read(C:\mirc\nicks.txt,w,%entry $+ *)
  var %toknum = $numtok(%linenum,44)
  var %N = 1
  var %preline
  while (%N <= %toknum) {
    if (%N = 1) {
      var %firsttok = $gettok(%linenum,%N,44)
    }  
    elseif ($right($gettok(%linenum,%N,44),8) isnum) {
      var %goodtok =  $gettok(%linenum,%N,44) $+ $chr(44)
    }
    else { 
      unset %goodtok
      var %badtok = %badtok + 1    
    }
    var %preline = %preline $+ %goodtok
    inc %N  
  }
  var %newline = %firsttok $+ $chr(44) $+ %preline
  echo -s line written
  write -al %entry C:\mirc\nicks.txt %newline %newstuff
  if (%badtok > 1) { echo -s %badtok tokens fixed }
  else { echo -s 0 tokens fixed }
}
Posted By: captain_comic Re: Problem with alias - 17/01/06 07:04 AM
Unfortunately you didn't tell us what happens if you run the script. I guess your script keeps the bad tokens and adds the good tokens.
If you want to remove tokens, i.e. rewrite a line with good tokens as far as I understand your script, you should use write -l %entry ... in the fixile alias instead of write -al %entry .... From mIRC help file: The -a switch indicates that mIRC should append the line of text you specified to the existing text of the specified line.
Posted By: bwr30060 Re: Problem with alias - 17/01/06 02:05 PM
I changed the write -al to -l. I caught that after I had posted. I'm still not totally sure what the script is doing. Some problems I have noticed is that it is supposed to echo how many tokens were fixed, and it always says 0. But when I look in the file, it appears that sometimes tokens are gone, because I can see double commas. I just looked over the file this morning, and another problem is that it is writing spaces after the commas. Thanks for any help. I know it's alot to look at, but I can't seem to fix it.
Posted By: captain_comic Re: Problem with alias - 17/01/06 02:43 PM
Indeed it is a lot and there is also a lot wrong with it! For instance (I overlooked that one at first) you use in de fix alias: "var %badtok = %badtok + 1" . This should be "inc %badtok". This will fix the 0 badtoks you get. The extra comma's are probably caused by statements like "set %join.newnick $chr(44) $+ $nick %join.time" were you insert a comma yourself. I advise you to read the helpfile carefully. Search for "$addtok", that makes life a lot easier. By the way, you call aliases with "$fixfile(param1,param2)". Normally you should use that format if you want to return something from that alias, like "var %x = $fixfile(param1,param2)". If you don't want to return a value you should use "fixfile param1 param2".

O, I almost forgot, there is some other thing I overlooked. You must add "$+" after "write -l": "write -l $+ %entry C:\mirc\nicks.txt %newline %newstuff"
Posted By: bwr30060 Re: Problem with alias - 17/01/06 03:09 PM
Thanks for the help. I need to look into tokens a bit more. As for the "write -l" thing, it actually works for me doing it the way I have it without the $+. I'll make the change to the %badtok statement today and see what that does. Thanks again.
Posted By: bwr30060 Re: Problem with alias - 17/01/06 03:09 PM
Thanks for the help. I need to look into tokens a bit more. As for the "write -l" thing, it actually works for me doing it the way I have it without the $+. I'll make the change to the %badtok statement today and see what that does. Thanks again.
Posted By: captain_comic Re: Problem with alias - 17/01/06 03:15 PM
From mIRC's helpfile: The -l# switch specifies the line number where the text is to be written.
The -l and the linenumber to write to should be without a space between them!
Posted By: bwr30060 Re: Problem with alias - 17/01/06 03:52 PM
I read about -l and I know that if you're using an actual number it should look like "-l4" but I'm using a variable, and it writes to the correct line when I use the space. Thanks for the help though.
Posted By: captain_comic Re: Problem with alias - 17/01/06 04:04 PM
Well, well, reading the mIRC helpfile doesn't always help! I tested it now and you are right, but also write -l 3 <filename> <text> works. So, with space, without space, with number or variable, it is all fine for mIRC. Which one would be quicker I wonder, and how many nanoseconds? grin
Posted By: bwr30060 Re: Problem with alias - 17/01/06 04:21 PM
LOL, I'm not too worried about nanoseconds. grin I added that "inc %badtok like you suggested and it does increment the number. I found that I think it doesn't reset it though with just using that line, which confuses me. I thought that using var instead of set would reset everything until the next time it's used. It looks like it's incrementing the number each time the alias is run. If I add "var %badtok" to the line before the loop, will that re-declare the variable and make it 0? Thanks.
Posted By: captain_comic Re: Problem with alias - 17/01/06 04:27 PM
Anything declared with var will be unset after the script has finished and redeclared if your script encounters var again.
© mIRC Discussion Forums