Pulling from an external file.

Posted by BenTrafford on Tue 03 Aug 2010 12:10 PM — 3 posts, 14,149 views.

#0
I'm guessing someone has done this, so I'm being lazy and hoping to save some time.

I've got a file. In this file, there is one MUSH command to each line. I'd like to open the file; go through the lines, one by one, pausing between each command to let it execute.

Does anybody have any code they'd care to share?
Australia Forum Administrator #1
For a start, under the Input menu there is an option "Send File" - that lets you send a disk file to the MUD.

However assuming you want to do this often in response to an alias (or some other reason) the aliases below will do it:


<aliases>
  <alias
   match="com"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

stop_sending = false

wait.make ( function ()

  for line in io.lines (GetInfo (56) .. "commands.txt") do
    if line ~= "" then
      Send (line)     
      wait.time (0.5)
    end -- if
    if stop_sending then
      return
    end -- if
  end 

  ColourNote ("cyan", "", "Sending file complete.")
end ) -- end wait.make function

</send>
  </alias>

  <alias
   match="stop_com"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

stop_sending = true
ColourNote ("cyan", "", "Stopped sending file.")

</send>
  </alias>
</aliases>


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


The first one reads in the file "commands.txt" in the MUSHclient installation directory (change as required) and then sends each line to the MUD, with a 0.5 second pause. Change the 0.5 to whatever you want.

It also tests a "stop_sending" variable (which it initially clears). This lets the second alias be used to stop the sending. For example, if the file takes a couple of minutes to slowly send, and you change your mind, type "stop_com" to stop the sending process.
#2
That worked! Thanks a bunch, Nick!