mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 4
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Aug 2004
Posts: 4
The following is supposed to delete the third token in a line if that token matches some criteria. As it is now, it doesn't or it randomly deletes correct lines. How come?

Code:
on *:TEXT:!del*:%m.channel:{ 
  set %m.quitter3 $nick
  set -u30 %m.diderase. [ $+ [ %m.quitter3 ] ] 0
  set -u30 %m.loopedDe1 [ $+ [ %m.quitter3 ] ] 1

w hile (%m.loopedDe1 [ $+ [ %m.quitter3 ] ] <= $lines(%m.filepath)) {

set %m.trash3 $read(%m.filepath,%m.loopedDe1 [ $+ [ %m.quitter3 ] ])

if ($gettok(%m.trash3,3,32) == %m.quitter3) { 
echo -s 4 %m.quitter3 found on line: %m.loopedDe1 [ $+ [ %m.quitter3 ] ] 

[color:red] 
write -dl $+ %m.loopedDel [ $+ [ %m.quitter3 ] ] %m.filepath
[/color] 

notice %m.quitter3 Erased from list > $read(%m.filepath,%m.loopedDe1 [ $+ [ %m.quitter3 ] ])

set %m.diderase. [ $+ [ %m.quitter3 ] ] 1
echo -s erased %m.quitter3 on request.
    }

inc %m.loopedDe1 [ $+ [ %m.quitter3 ] ] 1

  }
  ; while ends

if (%m.diderase. [ $+ [ %m.quitter3 ] ] == 0) { notice %m.quitter3 Didn't find an entry to erase. }

}
  


Or...if the above is a mess: What's the best way to check every line in a file for a %variable and delete all lines containing that exact variable? (File won't be bigger than 100 lines).

Joined: Dec 2002
Posts: 271
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
this works just fine, i added a set %m.filepath, but you may already have that somewhere else. the file contents looked something like: [something] [something] [nick]
[nick] being the nick of the user who triggered the on text event...

on *:TEXT:!del*:%m.channel:{
set -l %m.quitter3 $nick
set -l %m.diderase. $+ %m.quitter3 0
set -l %m.loopedDe1 $+ %m.quitter3 1
set -l %m.filepath testing.ini
while ([ [ $+(%,m.loopedDe1,%m.quitter3) ] ] <= $lines(%m.filepath)) {
set -l %m.loopedel.temp [ [ $+(%,m.loopedDe1,%m.quitter3) ] ]
set -l %m.trash3 $read(%m.filepath,%m.loopedel.temp)
if ($gettok(%m.trash3,3,32) == %m.quitter3) {
echo -s 4 %m.quitter3 found on line: %m.loopedel.temp
write -dl $+ %m.loopedel.temp %m.filepath
notice %m.quitter3 Erased from list > %m.trash3
set -l %m.diderase. $+ %m.quitter3 1
echo -s erased %m.quitter3 on request.
}
inc %m.loopedDe1 $+ %m.quitter3 1
}
; while ends
if ([ [ $+(%,m.diderase.,%m.quitter3) ] ] == 0) { notice %m.quitter3 Didn't find an entry to erase. }
}



ScriptA:

[28/8 2:41:07a] <NightChill[afk]> !del *
[28/8 2:41:09a] -NightChillz- Erased from list > this place NightChill[afk]

ScriptB:

NightChill[afk] found on line: 71
-
[28/8 2:41:08a] -> -NightChill[afk]- Erased from list > this place NightChill[afk]
-
erased NightChill[afk] on request.

Joined: Aug 2004
Posts: 4
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Aug 2004
Posts: 4
Night Thank you for helping out... yes, the %filepath was set somewhere else. The problem is that the error is still around. Check this out and do these 3 tests and you'll probably also get the same error. Each case first shows what i had in the file that was going to be serached/deleted. (Please use a txt-file and not an ini, maybe it gives different results). In the last case, I also show what was left in the file. Check it out:

CASE 1 - Works - All annabella1 were deleted

128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone



CASE 2 - Works - Allaannabella1 were deleted

128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone

case o3 - Doesn't work

What was in the file before !del:

128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
78/08 00:11 annabella1
1028/08 02:25 noone
78/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
48/08 00:11 annabella1
528/08 03:20 noone
628/08 03:20 noone
78/08 00:11 annabella1
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
118/08 00:11 annabella1
1228/08 01:53 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
78/08 00:11 annabella1
1028/08 02:25 noone
78/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone

What was in the file after !del:

128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
528/08 03:20 noone
628/08 03:20 noone
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
1228/08 01:53 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
528/08 03:20 noone
628/08 03:20 noone
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
1228/08 01:53 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
118/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
528/08 03:20 noone
628/08 03:20 noone
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
1228/08 01:53 noone
128/08 01:38 noone
228/08 01:02 noone
38/08 00:11 noone
528/08 03:20 noone
628/08 03:20 noone
828/08 03:20 noone
928/08 02:26 noone
1028/08 02:25 noone
1228/08 01:53 noone
118/08 00:11 annabella1
118/08 00:11 annabella1
118/08 00:11 annabella1
1028/08 02:25 noone
118/08 00:11 annabella1
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone
1028/08 02:25 noone


..the above was tried twice, both times with the same result.
It seems as the detection of what lines should be erased is 100% accurate, but that the actual erasing in the file with /write doesn't work.

Does anybody have an idea on why?

Joined: Dec 2002
Posts: 271
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
Alright, i found the little problem, you see, the code above reads a line, and if there is a match in that line, delete it. and whethere or not there was a match the var is increased... but if we delete a line, we dont want to increase the var because the line that was just matched and deleted now contains a new value, and thats where the error would occur, but only if there was two consecutive matching lines in the file. the below code with a minor adjustment works fine:


on *:TEXT:!del*:%m.channel:{
set -l %m.quitter3 $nick
set -l %m.diderase. $+ %m.quitter3 0
set -l %m.loopedDe1 $+ %m.quitter3 1
set -l %m.filepath file.txt
while ([ [ $+(%,m.loopedDe1,%m.quitter3) ] ] <= $lines(%m.filepath)) {
set -l %m.loopedel.temp [ [ $+(%,m.loopedDe1,%m.quitter3) ] ]
set -l %m.trash3 $read(%m.filepath,%m.loopedel.temp)
if ($gettok(%m.trash3,3,32) == %m.quitter3) {
echo -s 4 %m.quitter3 found on line: %m.loopedel.temp
write -dl $+ %m.loopedel.temp %m.filepath
notice %m.quitter3 Erased from list > %m.trash3
set -l %m.diderase. $+ %m.quitter3 1
echo -s erased %m.quitter3 on request.
[color:blue] continue

}
inc %m.loopedDe1 $+ %m.quitter3 1
}
; while ends
if ([ [ $+(%,m.diderase.,%m.quitter3) ] ] == 0) { notice %m.quitter3 Didn't find an entry to erase. }
}

[/color]


The /continue command is placed inside the if statement because we know that if we match a line and delete it, we want to run the loop again without changing any variables(/help /continue for more info on this command)

Joined: Aug 2004
Posts: 101
D
Vogon poet
Offline
Vogon poet
D
Joined: Aug 2004
Posts: 101
Check this out too:
(file2.txt is a temp file where we store the results. Then we copy it over the original file.txt)
Code:
on *:TEXT:!del*:%m.channel:{
  set %m.quitter $$1 
  ;[color:green]Filter file.txt through the alias m.del[/color]
  filter -fkn file.txt m.del * 

  ;[color:green]If result file is as big as initial file, no entries were found![/color]
  if $lines(file.txt) == $lines(file2.txt) { notice %m.quitter Didn't find an entry to erase. }
  ;[color:green]Else copy temp file to original[/color]
  else { .copy -o file2.txt file.txt }

  ;[color:green]Cleanup: Unset the global var and delete temp file[/color]
  unset %m.quitter 
  .remove file2.txt 
}

alias m.del { 
  tokenize 32 $1 
  ;[color:green]$1 is line number (due to -n filter switch)[/color]
  if $4 != %m.quitter { 
    ;[color:green]Entry doesn't match so write it to temp file[/color]
    write file2.txt $2- 
  } 
  else {
    ;[color:green]Entry matches (You actually do nothing...)[/color]
    echo 4 -s %m.quitter found on line: $1
    notice %m.quitter Erased from list &gt; $2-
    echo -s Erased %m.quitter on request
  }
} 


Maybe I wake up one day to notice that all my life was just a dream!
Joined: Aug 2004
Posts: 4
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Aug 2004
Posts: 4
Night:

You're correct. I also just tried it and it works like a charm. =)
Haven't used the /continue command before, nice learning something new.

Thank you all for helping out, it's great when people are actually active in these kind of forums.. If I was rich I'd send you all some, but you'll have to do with my love ; )


Link Copied to Clipboard