mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2015
Posts: 2
F
Bowl of petunias
OP Offline
Bowl of petunias
F
Joined: Jul 2015
Posts: 2
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.

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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)


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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.

Joined: Jul 2015
Posts: 2
F
Bowl of petunias
OP Offline
Bowl of petunias
F
Joined: Jul 2015
Posts: 2
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.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard