Saving to a log file via script?

Posted by Dragoness on Sat 30 Oct 2004 05:56 PM — 12 posts, 41,259 views.

#0
Hi there, I am a newbie about this so I have no clue how to do what I need.

I need to capture a specific line:

Warmth flows through you as the chants of this circle reach the gods, restoring <exp amount> experience to <player>.

to a logfile, with the time if possible. The line is output when I type in the command lifechant <person name> Can this be done? If so can anyone please tell me how to do this.

Thanks in advance.
Dragoness.
USA #1
I believe the standard send_to_notepad does exactly that. There should be dozens of examples here on the board and at least 1 in the scripting/trigger helpfiles.
USA #2
It's sendtonotepad, no underscores. And the problem with that is you have to 'remember' to save it (which you CAN do via scripting, so its not nessisarily a large problem), well and the fact that you have an open window.

A better solution (albeit more complicated) would be to use FSO and just append to the file.
#3
Ok thanks, I had a look at the examples but I am not sure how to incorporate them into anything, where to put what.

What is the FSO thingy?

Thanks again
Dragoness.
USA #4
FSO is File Scripting Object. Search the forums, and the VBscript help file (you can download it from the same page you downloaded the other script languages on the MC site) and youll get a lot of examples.

As for using it, depending on how youre going about it, it'll be different.

Your trigger however, will be something like this (not accounting for spaces, and youd probably be better off with a regexp):
Warmth flows through you as the chants of this circle reach the gods, restoring * experience to *.

and then you either put your script (like sendtonotepad and savenotepad in the send box and then the "send to" box gets set to script, or you put it in a scriptfile and then use the "script" box to call the routine.
#5
Thanks for your information, but do you know how to setup those sendtonotepad and savenotepad in mushclient? I have been trying to find instructions but I can't seem to figure it out. Do I copy those functions to the varibles in mushclient or is that the wrong track?

Thanks again
Dragoness.
USA #6
Youd put them in your "send" box (of the trigger) and "send to" script.

So itd be...
SendToNotepad "LogWindow", "Lets start a log" & VBCRLF
to send to it (and start it)
So if you had a trigger itd be:
SendToNotepad "LogWindow", "%0" & VBCRLF
(%0 is the full line that matched)

and then to save (whether you want to do it at the same time, or in a seperate thing) use this:
SaveNotepad "LogWindow", "C:\Path\logfile.txt", 1
That will save over the old one, so if you start a new session, you'll lose older stuff (unless you change the log name accordingly).

I believe OpenLog (I was perusing the function lits) opens a log, and then writes things to it (all the output), but if it doesnt, then that would be better. Or you could open the log, write to it, and then close it again. Then you could append, and not worry about overwriting stuff.
(Like this:
OpenLog "logfile.txt", true
writelog "%0"
CloseLog
that... should work. Assuming you have no other log file open. And that would be better, and cleaner. And you wouldn't have to worry about the next paragraph.

Also, notepad windows fill up over time. Theres a plugin regarding this I believe... Search for "notepad full" or something in this forum.
#7
Hi there,
I set this in my send box:

OpenLog "C:\path\logfile1.txt", true
writelog "%0"
CloseLog

with the trigger set to
Warmth flows through you as the chants of this circle reach the gods, restoring * experience to *.

But I am not getting anything in the directory I assigned.

I have send to set to script and enable scripting is checked and it is set to vbscript.

Did I miss something?

Thanks again
Dragoness.
USA #8
Do you have the logging menu set up?
I dont know why it might be an issue. But with it you can also add the time to the beginning of the line.

Check to see if your trigger is matching. Either change it to change the line's color, or turn on trace. I suggest the former.

But no, assuming you actually have a path instead of 'path', and that its a valid one (I dont know if MC will make a directory or not) then I don't think that that is the problem.
#9
Humm I haven't turned a log on if that is what you mean, if it is not I am not sure. If it is then doh :P
Dragoness
Australia Forum Administrator #10
You say you want to log certain messages, so turning on the log file would be a logical first step.

You could go to File menu -> Log Session, to turn logging on.

However if you only want to log certain lines then (in the dialog box that appears) uncheck "log output", "log commands" and "log notes". (In other words, log nothing). A confirmation dialog will appear asking if this is what you meant.

Then, make a trigger that matches the lines you want to capture, eg.


Match: Warmth flows through you as the chants of this circle reach the gods, restoring * experience to *.

Send: writelog now & " %0"
Send to: script


This will send the matching lines to the log file, with the date and time in front of them.
#11
Ok thanks, got it working.

You have been wonderful!

Dragoness