command line grouping (alias help)

Posted by SKYY on Fri 18 Apr 2008 05:52 PM — 3 posts, 19,821 views.

#0
I need to write some sort of alias that finds any command or commands that are input between curvy brackets {}, and that plays well with other plugins like multiple_send, for example.

For example, if I input this:

#12 {buy 20 heal;empty bag @container;drop bag}

I want the alias to send the following:

buy 20 heal
empty bag @container
drop bag
buy 20 heal
empty bag @container
drop bag
buy 20 heal
empty bag @container
drop bag
... (to 12)

I've tried messing with this before, but it's totally beyond my scripting capabilities thus far. Obviously, I already have the ";" character set to be my separator, but that doesn't particularly help this alias.

Any clue on where to start with this one?
Australia Forum Administrator #1
See http://mushclient.com/faq point 47, which pretty much covers all that.

However the ideas there vary slightly from what you presented.

One complexity is in your example:


#12 {buy 20 heal;empty bag @container;drop bag}


Now if you have ';' as the command stack character, then the line you type is broken up *before* it goes to the alias. In other words, it will become:


#12 {buy 20 heal
empty bag @container
drop bag}


Now you can see this won't work properly, as none of those lines will make much sense. The plugin presented in the thread above (Repeat_Command.xml) will handle the command stacking alright, and it doesn't need the braces.

So you could type this:


;#12 buy 20 heal;empty bag @container;drop bag


Note the initial ';' which stops MUSHclient breaking up the line at the subsequent semicolons, and thus the whole line goes to the plugin, which then does everything 12 times.

Also note you don't need the braces.

Another approach is to turn command stacking off in the commands configuration, and let the plugin do it. To do that, change in the plugin the lines:


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


to:


-- execute (send to command processor) the command
for i = 1, %1 do
  string.gsub ("%2", "[^;]+", Execute)
end -- for loop


What that does is break up the line at semicolons, and send each one to Execute (so aliases will be processed).

However for this to work you have to turn command stacking off. Then you could just type:


#12 buy 20 heal;empty bag @container;drop bag


This is the simplest, because you don't need a leading semicolon, and you don't need the braces around the commands.
USA #2
I have long since used a loop alias, and have always just doubled the command stacking character, and it sends the command list to be 'executed'. In doing it this method i have even stacked loops within loops, so something like this.

loop 4 Command1;;Command2;;loop 3 Command3;Final Command Here

I have used this in many ways, grabbing items, dropping things, and even enchanting items.

You might try that method also.

-Onoitsu2