mIRC Homepage
Posted By: freakbabyblues Need help with reading files... - 26/07/15 10:44 PM
I'm very new to scripting and I've searched all over and ever document I've come across has been missing at least one bit of vital information.

I would like to read a line of text from a file, but where do I place the file that mIRC can find it? Or, if I can place it anywhere, how do I format the file path?

For context, I'd like to make a document containing a list of greetings and a script that compares incoming comments to that list and outputs a reply.
Posted By: Nillen Re: Need help with reading files... - 27/07/15 09:39 AM
If you put it in the mircdir, type " //run $mircdir " then you can simply just type the file name, let's say it's "test.txt" in the scripts. Otherwise you will need to use the whole path to the file like $qt(C:\Users\Nillen\Desktop\test.txt)
Posted By: Khaled Re: Need help with reading files... - 27/07/15 12:04 PM
Expanding on Nillen's reply: in the scripting language, you can also use partial paths in commands and identifiers and these will be relative to $mircdir. This means that if you place the file cow.txt in $mircdir, you can access it using just $read(cow.txt). If you place cow.txt in folder "moo" in $mircdir, you can access it using $read(moo\cow.txt). In other words, you do not need to specify the full path, which makes the script more portable.
Posted By: freakbabyblues Re: Need help with reading files... - 28/07/15 01:04 AM
Thanks! Now I just need to figure out how to read a text file and spit out a random line. I'd think $read would serve my purpose but I've yet to find a proper code sample and don't know how to use it in context.
Posted By: Wims Re: Need help with reading files... - 28/07/15 01:12 AM
Khaled's example will actually do just that, return a random line from the file.
$read by default evaluates the line as though it was a line of code (if the line contains "$me", it will be evaluated to your nickname, this can be and is often the case, not desired).
$read will also use the first line in the file if it's a number, to speed up processing, where that number should indicate the number of line in the file, this is also usually not desired (an old feature), when the file's content is not known in advance.
The 'n' switch will prevent the evaluation, and the 't' switch will prevent mIRC from taking the first line as the the total number of lines in the file, if it's a number.
Check the help file for more information by typing in mIRC /help $read

$read(myfile.txt,tn) is probably what you are looking for smile
© mIRC Discussion Forums