Mudlet Append to Notepad

Share your scripts and packages with other Mudlet users.
Post Reply
solao
Posts: 5
Joined: Wed Oct 19, 2016 4:27 am

Mudlet Append to Notepad

Post by solao »

In MUSHClient I would use the below code to insert into a notepad file. How would I do that in Mudlet?


I have a map on mode which appends the directions as i enter them into the notepad, and a modification of the track command that stores the path resulting from track into a notepad file. Then I can just copy/paste from there into my directions database.

Code: [show] | [select all] lua
     AppendToNotepad("Tracking", string.sub("%1", 1, 1) .. ";")

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Mudlet Append to Notepad

Post by Jor'Mox »

So, for Mudlet, you would need to handle opening and closing the file, in addition to the actual writing. I don't know how much of a performance hit there would be if you were opening and closing the file every time you wanted to append a single character, so you may want to consider only appending at some logical break point, such as when you complete a path, as opposed to at each step. Instead, you would just store the path in a string variable until it was complete, and then write it all at once. Alternately, you could open the file when you first started keeping track of your movements, write to it at each step, and then close it at the end. Regardless, this would be the code to handle opening, appending to, and then closing the file.
Code: [show] | [select all] lua
local file = io.open("full path to file, with file name","a")
file:write("string to write")
file:close()
Or to use something akin to your example:
Code: [show] | [select all] lua
local file = io.open(getMudletHomeDir().."/Tracking.txt","a")
file:write(string.sub(matches[2],1,1)..";")
file:close()

Post Reply