mIRC Homepage
Posted By: phoenix7_1025 $read without repetition - 05/12/05 01:02 AM
$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.
Posted By: RusselB Re: $read without repetition - 05/12/05 02:14 AM
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.
Posted By: schaefer31 Re: $read without repetition - 05/12/05 02:15 AM
You can delete the line by putting this after the call to $read

write -dl $+ $readn yourfile.txt
Posted By: RusselB Re: $read without repetition - 05/12/05 02:47 AM
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.
Posted By: DaveC Re: $read without repetition - 06/12/05 05:19 AM
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
Posted By: RusselB Re: $read without repetition - 06/12/05 06:19 AM
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
© mIRC Discussion Forums