"Nesting"?

Posted by Schoffy on Sat 25 Dec 2010 03:51 AM — 6 posts, 27,710 views.

#0
I'm trying to smash together a bunch of if statements (mostly because I don't know how to make anything else work for this). What I'm wondering is, am I doing this right, and if not, how should it look?

I have an alias called:

Quote:
^d(x|e|k|i|r|c|m|u|v|al|aa|ll|l|s|o|d|a|n|g|p)(x|e|k|i|r|c|m|u|v|l|s|o|d|a|n|g|p)$


And in this alias I'm trying to do this:

Quote:
if "%1" == "x" then
if "%2" == "x then"
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with xentio")
elseif "%2" == "e" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with eurypteria")
elseif "%2" == "k" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with kalmia")
elseif "%2" == "i" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with digitalis")
elseif "%2" == "r" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with darkshade")
elseif "%2" == "c" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with curare")
elseif "%2" == "m" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with monkshood")
elseif "%2" == "u" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with euphorbia")
elseif "%2" == "v" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with vernalius")
elseif "%2" == "l" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with larkspur")
elseif "%2" == "s" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with slike")
elseif "%2" == "o" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with voyria")
elseif "%2" == "d" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with delphinium")
elseif "%2" == "a" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with aconite")
elseif "%2" == "n" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with selarnia")
elseif "%2" == "g" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with gecko")
elseif "%2" == "p" then
Send ("envenom @weaponleft with xentio")
Send ("envenom @weaponright with prefarar")
end
elseif "%1" == "e" then
if "%2" == "x then"
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with xentio")
elseif "%2" == "e" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with eurypteria")
elseif "%2" == "k" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with kalmia")
elseif "%2" == "i" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with digitalis")
elseif "%2" == "r" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with darkshade")
elseif "%2" == "c" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with curare")
elseif "%2" == "m" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with monkshood")
elseif "%2" == "u" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with euphorbia")
elseif "%2" == "v" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with vernalius")
elseif "%2" == "l" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with larkspur")
elseif "%2" == "s" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with slike")
elseif "%2" == "o" then
Send ("envenom @weaponleft with "eurypteria")
Send ("envenom @weaponright with voyria")
elseif "%2" == "d" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with delphinium")
elseif "%2" == "a" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with aconite")
elseif "%2" == "n" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with selarnia")
elseif "%2" == "g" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with gecko")
elseif "%2" == "p" then
Send ("envenom @weaponleft with eurypteria")
Send ("envenom @weaponright with prefarar")
end
Australia Forum Administrator #1
Well I wouldn't do it that way. You can see it is really tedious to see what the end result will be. Try this:


<aliases>
  <alias
   match="^d(x|e|k|i|r|c|m|u|v|al|aa|ll|l|s|o|d|a|n|g|p)(x|e|k|i|r|c|m|u|v|l|s|o|d|a|n|g|p)$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

local venoms = {
  a = "aconite",
  c = "curare",
  d = "delphinium",
  e = "eurypteria",
  g = "gecko",
  i = "digitalis",
  k = "kalmia",
  l = "larkspur",
  m = "monkshood",
  n = "selarnia",
  o = "voyria",
  p = "prefarar",
  r = "darkshade",
  s = "slike",
  u = "euphorbia",
  v = "vernalius",
  x = "xentio",

-- and so on 

}

local left = venoms ["%1"]
local right = venoms ["%2"]

if not left then
  ColourNote ("white", "red", "Unknown venom code: %1")
  return
end -- if

if not right then
  ColourNote ("white", "red", "Unknown venom code: %2")
  return
end -- if

Send ("envenom @weaponleft with " .. left)
Send ("envenom @weaponright with " .. right)

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



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


You can see this is much shorter, and you can have any combination easily, and add more venoms by simply adding to the table.
#2
:) Thanks.

How would I go about making one of those optional?

Like... if I wanted to do just "dd", and have it use the same venom twice.

And, lastly (I hope), can something to the effect of

Quote:
SetVariable ("venomleft", ..left)


be done?
Australia Forum Administrator #3
Well, instead of matching on:


 match="^d(x|e|k|i|r|c|m|u|v|al|aa|ll|l|s|o|d|a|n|g|p)(x|e|k|i|r|c|m|u|v|l|s|o|d|a|n|g|p)$"


You could match on:


 match="^d([a-z])([a-z]?)$"


That makes the second wildcard optional.

Then when working out the venoms do this instead of what was there before:


local left = venoms ["%1"]
local right = venoms ["%2"] or venoms ["%1"]


That is, if it can't find venom %2 it tries to use venom %1.

Schoffy said:


And, lastly (I hope), can something to the effect of

SetVariable ("venomleft", ..left)

be done?


The symbol ".." is for concatenating (joining). If you don't want to join stuff just do:


SetVariable ("venomleft", left)

USA #4
Nick Gammon said:

local left = venoms ["%1"]
local right = venoms ["%2"] or venoms ["%1"]


That is, if it can't find venom %2 it tries to use venom %1.


Can be optimized to this, since you already got venoms["%1"]:

local left = venoms ["%1"]
local right = venoms ["%2"] or left
#5
Thanks guys. :)