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.
Entire forum
➜ MUSHclient
➜ General
➜ 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 page
Posted by
| Fraust
(5 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) 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 < 1 then
ColourNote ("white", "red", "Too few repeats specified (%1)")
return
end -- if
if %1 > 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) 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 | Top |
|
Posted by
| Fraust
(5 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) 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 "x" 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 < 1 then
ColourNote ("white", "red", "Too few repeats specified (%1)")
return
end -- if
-- check not more than 50 repeats
if %1 > 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 17 Feb 2008 02:14 AM (UTC) |
Message
| |
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.
27,814 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top