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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ "Nesting"?
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Schoffy
(3 posts) Bio
|
Date
| Sat 25 Dec 2010 03:51 AM (UTC) |
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 | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 25 Dec 2010 07:17 AM (UTC) |
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>
 |
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 | Top |
|
Posted by
| Schoffy
(3 posts) Bio
|
Date
| Reply #2 on Mon 27 Dec 2010 03:30 AM (UTC) |
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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 28 Dec 2010 08:37 AM (UTC) |
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 | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Tue 28 Dec 2010 09:14 AM (UTC) |
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 | 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.
21,059 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top