lua: sending a list of commands to a mud all while. a way to stop them mid way.

Posted by Etsuko on Sat 06 Jan 2024 12:07 PM — 3 posts, 8,392 views.

#0
hello everyone
I'm verry new to Mush client, and scripting. I wanted to ask a question. I want to do the following:
send a huge list of commands, with a delay in bitween each. and also an ability to stop the sequence if I send, lets say, stop. is this possible?
Australia Forum Administrator #1
Certainly it's possible. One way is to use the techniques described here:

http://www.gammon.com.au/forum/?id=4956

That shows how you can script doing stuff with pauses between things. In that script you could test a variable, and use an alias to set a "stop" variable. If that variable is set then the script could exit.

The commands themselves could be in a Lua table, or a huge block of text which you read a line at a time. For doing that, see:

http://www.gammon.com.au/forum/?id=6544

Or, you might read a file, and put the commands in that. Then read the file a line at a time. For file handling, see:

http://www.gammon.com.au/scripts/doc.php?general=lua_io
Australia Forum Administrator #2
Example code:


<aliases>
  <alias
   match="send_my_commands"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
require "wait"
wait.make (function ()
  stopCommands = false   -- variable to stop the loop
  f = io.input ("commands.txt")
  for line in f:lines () do
    Send (line)
    if stopCommands then
      break
    end
    wait.time (1)  -- wait a second
  end 
  f:close ()  -- close that file now
end) 
</send>
  </alias>

  <alias
   match="stop_my_commands"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
  stopCommands = true   -- variable to stop the loop
  Note "Command sending stopped"
  </send>
  </alias>

</aliases>




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


This would give you two aliases:

  • send_my_commands - start sending the contents of the file commands.txt
  • stop_my_commands - stop sending those commmands


I have put a one second delay between each command, you can change that, of course.