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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  "Nesting"?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

"Nesting"?

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Schoffy   (3 posts)  [Biography] bio
Date Sat 25 Dec 2010 03:51 AM (UTC)  quote  ]
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 25 Dec 2010 07:17 AM (UTC)  quote  ]
Message
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.

- Nick Gammon

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

Posted by Schoffy   (3 posts)  [Biography] bio
Date Reply #2 on Mon 27 Dec 2010 03:30 AM (UTC)  quote  ]
Message
:) 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?
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 28 Dec 2010 08:37 AM (UTC)  quote  ]
Message
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)


- Nick Gammon

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

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Reply #4 on Tue 28 Dec 2010 09:14 AM (UTC)  quote  ]
Message
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

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Schoffy   (3 posts)  [Biography] bio
Date Reply #5 on Mon 03 Jan 2011 01:23 AM (UTC)  quote  ]
Message
Thanks guys. :)
[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.


1,762 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]