Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Send to Notepad

Send to Notepad

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by BishopOsiris   USA  (55 posts)  Bio
Date Sat 19 Nov 2016 03:48 PM (UTC)
Message
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.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Sat 19 Nov 2016 04:04 PM (UTC)
Message
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

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #2 on Sat 19 Nov 2016 05:55 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 19 Nov 2016 09:30 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 19 Nov 2016 09:31 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #5 on Sat 19 Nov 2016 11:24 PM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 20 Nov 2016 12:27 AM (UTC)

Amended on Sun 20 Nov 2016 12:28 AM (UTC) by Nick Gammon

Message
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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #7 on Sun 20 Nov 2016 12:34 PM (UTC)
Message
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?
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #8 on Mon 21 Nov 2016 12:00 PM (UTC)
Message
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 '<'
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #9 on Tue 22 Nov 2016 11:43 AM (UTC)

Amended on Tue 22 Nov 2016 11:45 AM (UTC) by Fiendish

Message
Your fwrite is busted.
\Y is not a valid escape sequence, and \n should be \\n.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #10 on Tue 22 Nov 2016 05:30 PM (UTC)

Amended on Tue 22 Nov 2016 07:37 PM (UTC) by BishopOsiris

Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #11 on Tue 22 Nov 2016 08:45 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #12 on Tue 22 Nov 2016 08:46 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by BishopOsiris   USA  (55 posts)  Bio
Date Reply #13 on Tue 22 Nov 2016 11:44 PM (UTC)

Amended on Wed 23 Nov 2016 05:43 PM (UTC) by BishopOsiris

Message
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...
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #14 on Wed 23 Nov 2016 02:20 AM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


36,963 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.