mIRC Home    About    Download    Register    News    Help

Print Thread
How to get Random lines from a text file? #2348 18/12/02 12:59 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Greetings,

I've heard there are random commands in mIRC but haven't found them yet. What are they?

How would I call and read, posting into the channel random lines from a text file?


Thanks for your time and consideration,
MDA

Re: How to get Random lines from a text file? #2349 18/12/02 01:01 AM
Joined: Dec 2002
Posts: 18
W
watcher Offline
Pikka bird
Offline
Pikka bird
W
Joined: Dec 2002
Posts: 18
$read(path\file.txt)


-watcher
Re: How to get Random lines from a text file? #2350 18/12/02 01:04 AM
Joined: Dec 2002
Posts: 27
NeX Offline
Ameglian cow
Offline
Ameglian cow
Joined: Dec 2002
Posts: 27
Hi,
to make you creat a txt file with this command
/write -a file.txt your text

-a = Go to the next line
then : //say $read(file.txt)

you can write this : /help $read or /help /write

NeX smirk


__NeX»»» smirk
Re: How to get Random lines from a text file? #2351 18/12/02 01:24 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Greetings Nex,

Sorry my post was confusing. I have a text file already written composed of X lines of text. I want to be able to read lines 1 thru X or any composing X, one at a time in a random fashion.


Thanks for your consideration and time,
MDA

Re: How to get Random lines from a text file? #2352 18/12/02 01:30 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Greetings Watcher,

Sorry my post was confusing. I have a text file already written composed of X lines of text. I want to be able to read lines 1 thru X or any composing X, one at a time in a random fashion.

$read(path\file.txt) will read the first line in the text file. Its not random. I want to read random lines of text from a existing text file. So that can be posted into the channel a message composed of line 7, followed by a timer to post later a message composed of line 5 etc.

Thanks for your consideration and time,
MDA

Re: How to get Random lines from a text file? #2353 18/12/02 01:45 AM
Joined: Dec 2002
Posts: 103
Pasmal Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2002
Posts: 103
$read(file) should be random,
From /help $read:

Quote:

$read(filename, [ntsw], [matchtext], [N])
Returns a single line of text from a file.

This identifier works in conjunction with the /write command.

//echo $read(funny.txt)

Reads a random line from the file funny.txt.
....


If you are still having problems, try:

set %lines $lines(file.txt)
set %text $read(file.txt,$rand(1,%lines))

But honestly $read(file.txt) should return a random line.

Re: How to get Random lines from a text file? #2354 18/12/02 02:11 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Quote:
$read(path\file.txt) will read the first line in the text file. Its not random.

This is incorrect. $read(filename.txt) is random with no other parameters supplied.

Quote:
I want to read random lines of text from a existing text file. So that can be posted into the channel a message composed of line 7, followed by a timer to post later a message composed of line 5 etc.

If I am understanding you correctly, you want to read a random line from the file and send it to the channel. Then, later, you want to read another line out of the same file and send it to the channel as well, so long as it's not already been sent to the channel. If this is what you mean, then here is an algorithm you might use.

Code:

;  Usage: /randline path\filename
;    /randline C:\My Documents\My Texts\How I Won The War Singlehandedly.txt
;    /randline kicks.txt
;
alias randline {
  var %File.Name = $+(",$$1,")
  var %Line.Text = $read(%File.Name)
  var %Line.Number = $readn
  if ($lines(%File.Name) == $numtok(%LineNumbers.Read,32)) unset %LineNumbers.Read
  while ($istok(%LineNumbers.Read,%Line.Number,32) {
    %Line.Text = $read(%File.Name)
    %Line.Number = $readn
  }
  set %LineNumbers.Read $addtok(%LineNumbers.Read,%Line.Number,32)
  msg $active %Line.Text
}

Note: Do not use this algorithm on a file with a large number of lines. Doing so will cause the script to gradually slow to a crawl as mIRC tries to randomly find a line number it has not used. Also, you could easily come up with the error /set line too long if you set a long string of line numbers into a single varialbe. This method is, therefore, unsuited to larger files.

Instead, if it is fairly important that the lines not be repeated before they have all been used and/or the number of lines in the file is large, then rather than using $addtok to append the line number to a variable's value, create a temp file from the master file you wish to use and delete the lines out of the temp file as you read them until all the lines are gone; then recopy the master file back into the temp file and continue.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: How to get Random lines from a text file? #2355 18/12/02 04:53 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Outstanding Hammer, NeX, Watcher and Pasmal!

My thanks to each.


Best Regards,
MDA

Re: How to get Random lines from a text file? #2356 18/12/02 09:27 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
The final project was far easier than I thought thanks to your kind and thoughtful suggestions.

#advs on
on *:START:./timeradv 0 30 /privmsg $active $read(adv.txt)
#advs end


Best regards and holidays to you each,
MDA

Re: How to get Random lines from a text file? #2357 18/12/02 10:17 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Oh HO! mad Writing another lame advertising script, are you? mad Well, I'm glad blush we were able to answer your scripting questions to your satisfaction. I'm ALSO very glad that you have left in the errors you have left uncorrected. smirk May you and your script be successfully banned from every IRC network on the Internet. grin


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: How to get Random lines from a text file? #2358 18/12/02 11:27 AM
Joined: Dec 2002
Posts: 111
F
Frog Offline
Vogon poet
Offline
Vogon poet
F
Joined: Dec 2002
Posts: 111
roflmfao, Hammer


Experience The Void.. Are You Ready?
Re: How to get Random lines from a text file? #2359 18/12/02 05:42 PM
Joined: Dec 2002
Posts: 843
P
Poppy Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: Dec 2002
Posts: 843
Well said, Hammer grin


Never compare yourself to others - they're more screwed up than you think.
Re: How to get Random lines from a text file? #2360 18/12/02 10:56 PM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Yur welcome to visit our chatrooms anytime,

As far as jumping to the moon in your lame comments and being banned, that's way out of line and neither what I do, nor what we use that routine for would prompt a system operator to ban us. The posted routine works fine, its stable and does a fine job.

I couldn't count the christian chatrooms that toss out random quotes of their bibles using a similar scripting routine and those folks are certainly not banned for doing so in their own chatrooms.

But, of course I was thanking the response I recieved in my quierys, its also human nature for others to tell someone to go break a leg.

We show the door in our chatrooms to probably 4 to 10 war kiddies per 24/hr period, regardless of their trash talking, clone flooding toys. Your'e welcome to visit and see who the hammer falls on anytime, day or night 24/7.

Regards,
MDA

Re: How to get Random lines from a text file? #2361 18/12/02 11:10 PM
Joined: Dec 2002
Posts: 843
P
Poppy Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: Dec 2002
Posts: 843
Oh please. Surely anyone visiting a trivia/games channel or as you suggest, a Christian channel (what's that got to do with the price of eggs, btw?) would expect it to be overflowing with scripted quotes/questions. People who go to 'ordinary' channels, just for a chat (yes, people chat on IRC!) do NOT.


Never compare yourself to others - they're more screwed up than you think.
Re: How to get Random lines from a text file? #2362 19/12/02 02:20 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Poppy,

I am the owner of five channels, 4 gateway chatrooms, one main chatroom. I don't go out spamming chatrooms for visitors. Others spam our chatrooms and are immediately kicked and banned, that's the code of conduct on many chat servers contracts. Any channel owner, and virtually all chatroom owners know that, its not appreciated, its not appreciated by them when that happens, its not appreciated by chatroom visitors and its slanderous to accuse someone of that. No one asked me, well where is this going to be used and how. I'm however immdiately accused of spamming, what a crock and indicative of the reflection of some sad individuals inner nature.

Your'e welcome to visit our chatrooms also Poppy, just leave the trash and accusations outside the door or you'd be tossed out like old trash. That invitation also stands as previously stated for Hammer and any other individual that wishes, all of whom I rather doubt would last a brief moment in any of our chatrooms making such statements and accusations. I find such outragious comments laughable.

We've logged about 5,000 visitors in the past 2 months thru our chatrooms. Not an extreme number but certainly a busy and active number of visitors. I certainly don't see us forcing anyone to stay in any of our chatrooms.

Again, as previously posted, I'm grateful for the assistance, the rhetorical slander is unfounded and over the top.


Regards,
MDA

Re: How to get Random lines from a text file? #2363 19/12/02 04:55 PM
Joined: Dec 2002
Posts: 843
P
Poppy Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: Dec 2002
Posts: 843
Well thanks for the invite, MDA - but I think I'll stay put, so that I can chat with people rather than a bot. However, I apologise for assuming you were trying to write a spamming script, but surely you agree that calling it 'ads.txt' was more than a tad misleading.


Never compare yourself to others - they're more screwed up than you think.
Re: How to get Random lines from a text file? #2364 20/12/02 04:21 AM
Joined: Dec 2002
Posts: 99
M
MDA Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Dec 2002
Posts: 99
Greetings Poppy,

Yes, I'm reading some lines from an adventure text into a chatroom and I can understand how that could possibily be misconstrued. Its a leap thou to take that routine, travel to someones chatroom and spam them, they would certainly be kicked and banned.
We have a hosting staff of over twenty individuals, with about 5-8 hosts active during the days and evening hours and about 1-3 hosts during the early morning hours. Chances of only being able to interact with our automated help system is less than 5% in most any 24 hour period.
The majority of our help menus are whisper based so they don't disrupt the main chatroom flow, topics and conversations. We do have a series of about 30 community website links thou that can be posted into the main chatroom to help our webtv visitors and born today computer chat visitors find specific areas in our community website as well as a specific and consise descriptions of each of those areas. Those series of items are sparingly used, and visitors are sometimes asked by the hosts to instead use the whisper menu items.
This month we'll log about 5,000 individuals visiting our chatrooms. The userlist is based upon their nicnames and their IP/Gatekeepers. Anyone can of course change their nicname but the userlist would not add them unless their IP/Gatekeeper also changed. I checked the user list last night and we were close to 4,000, I'm assuming we'll reach 5,000 unique visitors at the end of the month.
I can see the visitor flow drop when our IRC Clients are offline and unable to assit new visitors as well as our hosting staff. I can see the visitor flow drop when several of our mature and experienced hosts are sick or away. I don't see however our success as being just our implementations of our IRC Client bots. I do see success however with providing layers of interaction to help our visitors, our hosts and our community prosper.


Best Regards,
MDA

Re: How to get Random lines from a text file? #2365 20/12/02 11:34 AM
Joined: Dec 2002
Posts: 2,985
Watchdog Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
Your'e welcome to visit our chatrooms also Poppy, just leave the trash and accusations outside the door or you'd be tossed out like old trash.

You sound like a union shop steward. With that attitude towards people 5,000 in a month is all you are ever likely to get and I'm surprised it's that high. People's curiosity will run dry soon and your server will surely die.