[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Want an alias to repeat a command x times

Want an alias to repeat a command x times

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


Posted by Fraust   (5 posts)  [Biography] bio
Date Sun 10 Feb 2008 03:32 AM (UTC)
Message
I just starting using MushClient and have always been a Zmud user. My question is how I go about doing a repeat on the command line or in an alias/trigger.

For example. In Zmud I would have entered the following:

<command line> #7 drink potion

the output would have been 7 lines of drink potion.

Is there something similar for that in Mushclient?

Help!

Fraust
[Go to top] top

Posted by Nick Gammon   Australia  (23,017 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 10 Feb 2008 04:21 AM (UTC)
Message
There is a bit of a discussion about this here:

http://www.gammon.com.au/forum/?bbsubject_id=3311

A fairly good way is to simply add this alias (I have amended the one in the above thread a bit to use Lua, as that is now the recommended script language):


<aliases>
  <alias
   match="^#(\d+) (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Execute (EvaluateSpeedwalk ("%1 (%2)"))</send>
  </alias>
</aliases>


See http://mushclient.com/pasting for how to add this into your world.

The alias above uses EvaluateSpeedwalk to do things repeatedly (as in, you can do 4n or 4(burp)).

However that one fails if you have a bracket in the thing you are trying to do (as that will confuse EvaluateSpeedwalk). The version below simply does a loop, so that might be better:


<aliases>
  <alias
   match="^#(\d+) (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

for i = 1, %1 do
  Execute "%2"
end -- for loop

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


All that does is take the number you supply, and do the command that many times.

Maybe it is wise to check the repeat count is not too small or too big, this is my final version:


<aliases>
  <alias
   match="^#(\d+) (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if %1 &lt; 1 then
  ColourNote ("white", "red", "Too few repeats specified (%1)")
  return
end -- if

if %1 &gt; 50 then
  ColourNote ("white", "red", "Too many repeats specified (%1)")
  return
end -- if

for i = 1, %1 do
  Execute "%2"
end -- for loop

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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,017 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 10 Feb 2008 05:45 AM (UTC)

Amended on Sun 10 Feb 2008 05:46 AM (UTC) by Nick Gammon

Message
The reason I used "Execute" in the script is to send whatever you typed back through the command processor.

You could substitute "Send" for "Execute" but then whatever you type is literally sent (which may be OK).

The difference shows up if you use aliases or speedwalks.

Say for example you have an alias "healme" (which might do "drink potion").

If you want to be able to type:


#5 healme


Then you want to use the alias I posted above.

See:

http://www.gammon.com.au/scripts/function.php?name=Send

and

http://www.gammon.com.au/scripts/function.php?name=Execute

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fraust   (5 posts)  [Biography] bio
Date Reply #3 on Sun 10 Feb 2008 10:41 PM (UTC)
Message
Okay,

I think I understand what you did. I followed your suggestion and made the alias you posted, but now when I try do to #4 burp, I get the following.

Error number: -2147352567
Event: Execution of line 1 column 13
Description: invalid syntax

Line in error:

if 4 < 1 then
Called by: Immediate execution


Suggestion?
[Go to top] top

Posted by Nick Gammon   Australia  (23,017 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 11 Feb 2008 02:22 AM (UTC)
Message
I mentioned above that this alias was for the Lua script language. Is your scripting language set to Lua?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,017 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 17 Feb 2008 02:06 AM (UTC)
Message
I have turned my idea into a plugin, you can use this to achieve what you want:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, February 17, 2008, 2:05 PM -->
<!-- MuClient version 4.19 -->

<!-- Plugin "Repeat_Command" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Repeat_Command"
   author="Nick Gammon"
   id="7f69fe2f7913b2ac312ecbad"
   language="Lua"
   purpose="Repeats a command &quot;x&quot; times"
   date_written="2008-02-17 14:04:23"
   requires="4.00"
   version="1.0"
   >
<description trim="y">
<![CDATA[
To use, type:

#n command

This sends "command" n times to the MUD.

For example:

#3 kick kobold


]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="^#\s*(\d+) (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
-- check at least 1 repeat
if %1 &lt; 1 then
  ColourNote ("white", "red", "Too few repeats specified (%1)")
  return
end -- if

-- check not more than 50 repeats
if %1 &gt; 50 then
  ColourNote ("white", "red", "Too many repeats specified (%1)")
  return
end -- if

-- execute (send to command processor) the command
for i = 1, %1 do
  Execute "%2"
end -- for loop

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

</muclient>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,017 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sun 17 Feb 2008 02:14 AM (UTC)
Message
This plugin is now available on the plugins page:

http://www.gammon.com.au/mushclient/plugins/

Specifically, right-click to download this file:

http://www.mushclient.com/plugins/Repeat_Command.xml

Save that to disk and install it into MUSHclient using the File menu -> Plugins.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


26,334 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]