mIRC Home    About    Download    Register    News    Help

Print Thread
#136879 05/12/05 01:02 AM
Joined: Dec 2005
Posts: 1
P
Mostly harmless
OP Offline
Mostly harmless
P
Joined: Dec 2005
Posts: 1
$read(file.txt) will pull the random line that I want, but it still leaves the possibility that the same line will be pulled on subsequent calls. I haven't been able to find a way to either delete the line when it's pulled, or somehow mark it so it won't be pulled a second time. Anyone with more experience than I with it have any ideas? Thanks.

Last edited by phoenix7_1025; 05/12/05 01:03 AM.

I dare you to make less sense.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
A possibility for you to consider
Code:
on *:start:{
if !$hget(text) { .hmake text 100 }
if $exists(file.txt) { .hload -n text file.txt }
}
on *:text:!read:#:{
var %line = $r(1,$hget(text,0).items)
.msg $chan $hget(text,%line)
.hdel text %line
if !$hget(text,0).items { .hload -n text file.txt }
}
  


That will load your text file into a hash table, one line per item, with each item being numbered (same as the line numbers).
When the !read command is used a random item from the hash table is generated and used to get the line from the hash table.
When the hash table is empty (ie: all of the lines have been used) then it automatically refreshes itself from the text file.

In this way, it is impossible for the same line to be read twice, but it might appear so, if two (or more) lines are identical or very similar.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
You can delete the line by putting this after the call to $read

write -dl $+ $readn yourfile.txt

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
True, they could, but that would mean having to recreate the text file every time, or having a back-up copy of the text file stored elsewhere. With my code there's no need for the extra file.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
he said it was fine to delete the file in the original message, so it would be an acceptable and simple method.

PS you typoed!
$hget().item and not $hget().items

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Ooops...again...that seems to be a common typo for me...usually when I'm referencing 0 (which returns the number of entries in the hash table) <entries/items...both plural> blush


Link Copied to Clipboard