Alias which adds aliases

Posted by Nick Gammon on Sat 08 Apr 2006 12:37 AM — 5 posts, 25,787 views.

Australia Forum Administrator #0
This is further to a forum post about how to make an alias "like Tintin".

If you add this alias to your world, you can type something like:


#alias {h} {cast 'cure light'}


What this will do is create another alias, which matches on "h" and sends 'cure light'.

However it also allows for an optional player name, eg. "h nick", and then it sends "cast 'cure light' nick".


<aliases>
  <alias
   match="^\#alias \{(?P&lt;match&gt;[A-Za-z]+)\} \{(?P&lt;send&gt;.+)\}$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>do
  local result = 
    AddAlias ("%&lt;match&gt;", "^%&lt;match&gt;(?P&lt;target&gt; [A-Za-z]{1,}){0,1}$", 
              "%&lt;send&gt;%%&lt;target&gt;", 
               alias_flag.Enabled + 
               alias_flag.RegularExpression + 
               alias_flag.Replace, 
                "")

  if result ~= error_code.eOK then
     ColourNote ("white", "red", error_desc [result])
  else
     ColourNote ("white", "green",
                 "Alias '%&lt;match&gt;' added which sends '%&lt;send&gt;'")
  end -- if

end -- do</send>
  </alias>
</aliases>



The alias is created with the same name as the matching string (eg. an alias "h" will be named "h") so that you can easily replace an existing one, in case you change what "h" is going to send.

This alias is scripted in Lua, you would need to enable scripting and set the script language to Lua. If you are using VBscript or some other language the alias will be the same, and you need to rework the script syntax slightly.
#1
So I was using this alias to add a bunch of aliases that use command stacking within them. I'll give you a example of what I was adding using the alias you created above (note that I modified just the name of your alias which was #alias to #ALIAS for my own personal preference)

#ALIAS {blinloth} {linw;wlinmid;wmidpel;wpelosg;wosgroi;wroimid;wmidloth;wloth}

This alias would add fine, which was great. Each of those commands linw, wlinmid,wmidpel etc each contain their own set of commands. After adding the alias blinloth with the alias you created above and then typing it into the command line with command stacking enabled and the prefix set to ;
all I was getting sent to the output was linw;wlinmid;wmidpel;wpelosg;wosgroi;wroimid;wmidloth;wloth without each of the commands contained within those aliases to fire off. Is it even possible to do what I'm trying to do using this alias you created or will I have to go ahead and manually add them all? If you're having a hard time understanding exactly what I'm trying to do, I'll sit down and try to find another way to explain it if I do get any replies at all. Thanks as always!
Australia Forum Administrator #2
All you need to do is amend the alias to "send to execute", which makes the individual alias items be re-evaluated by the MUSHclient command processor. Like this:


<aliases>
  <alias
   match="^\#alias \{(?P&lt;match&gt;[A-Za-z]+)\} \{(?P&lt;send&gt;.+)\}$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>do
  local result = 
    AddAlias ("%&lt;match&gt;", "^%&lt;match&gt;(?P&lt;target&gt; [A-Za-z]{1,}){0,1}$", 
              "%&lt;send&gt;%%&lt;target&gt;", 
               alias_flag.Enabled + 
               alias_flag.RegularExpression + 
               alias_flag.Replace, 
                "")

  if result ~= error_code.eOK then
     ColourNote ("white", "red", error_desc [result])
  else
     ColourNote ("white", "green",
                 "Alias '%&lt;match&gt;' added which sends '%&lt;send&gt;'")
     SetAliasOption ("%&lt;match&gt;", "send_to", "10")
  end -- if

end -- do</send>
  </alias>
</aliases>



However I notice when trying it, that whilst the above works, if you use an argument it gets tacked onto the end, eg.


blinloth nick

--> sends:

linw
wlinmid
wmidpel
wpelosg
wosgroi
wroimid
wmidloth
wloth nick


See what I mean? The "nick" is only on the last one. However if you just do blinloth on its own it will be OK.

You could work around that, but I am just pointing it out, as what the current behaviour will be.
Poland #3
i have accelerator to firing alias to firing specjals

in tavern to sit down, entering ships, opening gates, and so on...

var SPEC1 contains string to output (filled by triggers)
and should be cleared after firing (SPEC1 = "")

<alias
name="specjal1"
match="^func1$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>SendSpecial(SPEC1,false,true,true,true)
SPEC1 = ""
</send>
</alias>

I cant use aliases as SPEC1, because they are sended directly to mud (can't send_to_execute, because i have to clear SPEC1)

how can use aliases in this alias?
Australia Forum Administrator #4
Use Execute which evaluates aliases.

eg.


Execute (SPEC1)   -- execute as command (processes aliases)
WriteLog (SPEC1)  -- optional - log the line (but the alias might log it anyway)
SPEC1 = ""