Send to Notepad

Posted by BishopOsiris on Sat 19 Nov 2016 03:48 PM — 15 posts, 53,258 views.

USA #0
I'm running MUSHClient on Windows 10 so I can't use the help files. I tried looking this up in the online documentation but had no luck there either. What I want to do is make a trigger that captures a line of text. For example, when I raise a level in my MUD I get this:

You raise a level!! Your gain is: 15/70 hp, 4/94 m, 14/164 mv 3/3 prac.

So I want to make a trigger: "You raise a level!!" so that every time I raise a level that line is captured and appended to a text file so that I have all my level gains for this character.
USA Global Moderator #1
Quote:
I'm running MUSHClient on Windows 10 so I can't use the help files
The online documentation is exactly the same content anyway.

Don't forget to also search the forum.

Maybe https://www.mushclient.com/forum/bbshowpost.php?bbsubject_id=9921
USA #2
I did search the forum and I saw that post but it didn't help... or I didn't understand it anyway. When I'm in the Trigger dialog box I can Send to: Notepad (append to) but there's no where for me to select the text file to send it to. I don't want to create a new text file for each line of text it captures. I want each line captured appended to the existing file that I've already created.
Australia Forum Administrator #3
The notepad isn't a file, it's a window. If you use the trigger option it sends to a window, either a new one each time or appending to one. The window name is "Trigger: (trigger name)". Later you can save that to disk if you want.

If you want to append to a disk file then you could use the Lua "io" functions to open the file if it isn't open (eg. for appending) and then write a line each time. Something like this:


<triggers>
  <trigger
   enabled="y"
   match="Exits: *"
   send_to="12"
   sequence="100"
  >
  <send>

f = assert (io.open (GetInfo (67) .. "test.txt", "a"))  -- open file for appending
f:write ("%0\\n")  -- write trigger data plus linefeed
f:close ()  -- close it

</send>
  </trigger>
</triggers>


This is a bit inefficient because it opens the file every time, but at least that way it is usually closed, and that way you can delete or rename it while it isn't actually in use.

GetInfo (67) returns the "worlds" directory, you can choose another directory for the file if you want.
Australia Forum Administrator #4
Bishoposiris said:

I'm running MUSHClient on Windows 10 so I can't use the help files.


There is a "MUSHclient_Help" plugin that ships with the client. You can read all the help files in the output window using that.
USA #5
Thanks Nick. I have 3 questions:

1. How do I use quote boxes and code boxes like you do?

2. You said "GetInfo (67) returns the "worlds" directory, you can choose another directory for the file if you want." I'm confused by this. Say the file I create is located at C:\Users\Bishop\Documents\MUD\MyMud. Would I write:

f = assert (io.open (GetInfo (67) .. "C:\Users\Bishop\Documents\MUD\MyMud\Myfile.txt", "a"))

3. If not how would I assign the file directory and what does GetInfo(67) have to do with it?
Australia Forum Administrator #6
Bishoposiris said:

1. How do I use quote boxes and code boxes like you do?


http://www.gammon.com.au/templates

Also:

http://www.gammon.com.au/forum/bbforumcode.php

Quote:

2. You said "GetInfo (67) returns the "worlds" directory, you can choose another directory for the file if you want." I'm confused by this. Say the file I create is located at C:\Users\Bishop\Documents\MUD\MyMud. Would I write:

f = assert (io.open (GetInfo (67) .. "C:\Users\Bishop\Documents\MUD\MyMud\Myfile.txt", "a"))


Omit the GetInfo, and you double the backslashes because of the way Lua works. Better is probably to use forward slashes:


f = assert (io.open ("C:/Users/Bishop/Documents/MUD/MyMud/Myfile.txt", "a"))


Quote:

3. If not how would I assign the file directory and what does GetInfo(67) have to do with it?



All GetInfo(67) does is return the directory name. Try doing:


print (GetInfo(67))


(You need to open up the scripting Immediate commands window - Ctrl+I to do this).
Amended on Sun 20 Nov 2016 12:28 AM by Nick Gammon
USA #7
Excellent. Two more thing. If the trigger data goes here:

f:write ("%0\n")  -- write trigger data plus linefeed


I'm assuming between the backslashes:

f:write ("%0\You raise a level!!\n")  -- write trigger data plus linefeed


Then whenever the MUD outputs that snippet the whole line will be captured and appended to the file?

Also, what if I wanted to insert additional text before the line in the text file? If the above works like I think it does then what I'll see in my text file for the first 3 levels is this:


You raise a level!!  Your gain is: 15/70 hp, 4/94 m, 14/164 mv 3/3 prac.
You raise a level!!  Your gain is: 16/86 hp, 6/100 m, 10/184 mv 3/6 prac.
You raise a level!!  Your gain is: 14/100 hp, 7/107 m, 11/205 mv 3/9 prac.


But what I really want to see is this:


Level 2: You raise a level!!  Your gain is: 15/70 hp, 4/94 m, 14/164 mv 3/3 prac.
Level 3: You raise a level!!  Your gain is: 16/86 hp, 6/100 m, 10/184 mv 3/6 prac.
Level 4: You raise a level!!  Your gain is: 14/100 hp, 7/107 m, 11/205 mv 3/9 prac.


How do I accomplish this?
USA #8
I'm getting an error trying to compile this code. This is what my code looks like:


<triggers>
  <trigger
   enabled="y"
   match="Exits: *"
   send_to="12"
   sequence="100"
  >
  <send>

f = assert (io.open ("C:/Users/Bishop/Documents/MUD/MyMud/Myfile.txt", "a"))  -- open file for appending
f:write ("%0\You raise a level!!\n")  -- write trigger data plus linefeed
f:close ()  -- close it

</send>
  </trigger>
</triggers>


And this is the error I'm getting:


[string "Immediate"]:1: unexpected symbol near '<'
USA Global Moderator #9
Your fwrite is busted.
\Y is not a valid escape sequence, and \n should be \\n.
Amended on Tue 22 Nov 2016 11:45 AM by Fiendish
USA #10
I tried:


f:write ("%0\\You raise a level!!\\n")


and


f:write ("%0\You raise a level!!\\n")


They both give me the same error as before. Not sure what you mean by

Quote:

\Y is not a valid escape sequence


If that's not corrected with \\Y then what's it looking for?

BTW I have a LUA book on it's way so hopefully it will shed some light on all of this.
Amended on Tue 22 Nov 2016 07:37 PM by BishopOsiris
Australia Forum Administrator #11
He means you put a backslash before the Y in You, which is not valid.

As for \\n, in "send to script" MUSHclient first interprets escape sequences itself, before the code hits Lua. You need to double the backslashes in "send to script". This doesn't apply if you use a script file or scripting in a plugin.
Australia Forum Administrator #12
Quote:

Also, what if I wanted to insert additional text before the line in the text file?


You can do whatever you want. You might use string.format to format the line.
USA #13
This script:


<triggers>
  <trigger
   enabled="y"
   match="Exits: *"
   send_to="12"
   sequence="100"
  >
  <send>

f = assert (io.open ("C:/Users/Bishop/Documents/MUD/MyMud/Myfile.txt", "a"))  -- open file for appending
f:write ("%0You raise a level!!\\n")  -- write trigger data plus linefeed
f:close ()  -- close it

</send>
  </trigger>
</triggers>


Simply will not compile. It keeps giving me this same generic error


[string "Immediate"]:1: unexpected symbol near '<'


Which really doesn't tell me anything.

I don't know what I'm doing wrong...
Amended on Wed 23 Nov 2016 05:43 PM by BishopOsiris
Australia Forum Administrator #14
Hmm, that isn't a script, that's a trigger.

Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


The script part is:


f = assert (io.open ("C:/Users/Bishop/Documents/MUD/MyMud/Myfile.txt", "a"))  -- open file for appending
f:write ("%0You raise a level!!\\n")  -- write trigger data plus linefeed
f:close ()  -- close it