How do I handle null %1 variables

Posted by Errigour on Sun 24 Jul 2011 09:03 PM — 6 posts, 27,191 views.

USA #0
I'm looking for something like The last question I asked accept it used numbers and only needed to be "heal *" but
this one is "^de( .*){0,1}$" and I can't make lua use
if %1 then <do something> else <do something else> end

if %1 then
  --do extra stuff
else
  --do repetitive stuff
end

or

if !%1 then
  --do repetitive stuff
else
  --do extra stuff
end


The following is what I am using the if statement for.

Alias:^de( .*){0,1}$

Send("cast '@castingspell'")

--I don't want this to happen if I type de by itself
--I don't want this to happen if I type de by itself
      Send("cast '@castingspell' %1")
      SetVariable("target", "%1")
      ColourNote("#0000ff", "#FFFFFF", string.format("Target set as: %s", GetVariable("target")))
--I don't want this to happen if I type de by itself
--I don't want this to happen if I type de by itself
Amended on Sun 24 Jul 2011 09:25 PM by Errigour
Australia Forum Administrator #1
This is the third time you have asked this, and twice before I referred you to FAQ #50.

Template:faq=50
Please read the MUSHclient FAQ - point 50.



Does that not explain things well? In what way is it lacking?

Inside FAQ #50 it mentions using this:


<aliases>
  <alias
   match="^heal( {1,}(.*)){0,1}$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
if "%2" == "" then
  Send ("cast healing touch self")
else
  Send ("cast healing touch %2")
end -- if
</send>
  </alias>
</aliases>


This is amazingly similar to what you are trying to do.

So to make the minor changes for your case it would be:


<aliases>
  <alias
   match="^de( {1,}(.*)){0,1}$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
if "%2" == "" then
  Send("cast '@castingspell'")
else
  Send("cast '@castingspell' %1")
  SetVariable("target", "%1")
  ColourNote("#0000ff", "#FFFFFF", 
             string.format("Target set as: %s", GetVariable("target")))
end -- if
</send>
  </alias>
</aliases>


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


If you can tell me how to improve the FAQ to make it clearer I would be grateful.
USA #2
nm thanks
Amended on Sun 24 Jul 2011 09:54 PM by Errigour
USA #3
It's hard for me to understand that stuff so I don't
soak in everything the page says but thank you.
#4
Nick Gammon said:

This is the third time you have asked this, and twice before I referred you to FAQ #50.

(faq=50)


Does that not explain things well? In what way is it lacking?

Inside FAQ #50 it mentions using this:


<aliases>
  <alias
   match="^heal( {1,}(.*)){0,1}$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
if "%2" == "" then
  Send ("cast healing touch self")
else
  Send ("cast healing touch %2")
end -- if
</send>
  </alias>
</aliases>


This is amazingly similar to what you are trying to do.

So to make the minor changes for your case it would be:


<aliases>
  <alias
   match="^de( {1,}(.*)){0,1}$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
if "%2" == "" then
  Send("cast '@castingspell'")
else
  Send("cast '@castingspell' %1")
  SetVariable("target", "%1")
  ColourNote("#0000ff", "#FFFFFF", 
             string.format("Target set as: %s", GetVariable("target")))
end -- if
</send>
  </alias>
</aliases>


(pasting)

If you can tell me how to improve the FAQ to make it clearer I would be grateful.

--------------------------------

Dear Nick, i'll appreciate if you could give me an example of this code but applied to a table that contains several objects: e.g.

instead of:
Send("cast '@castingspell' %1")

i would like to:
Send ("cast '[protection|benediction|sanctuary]')

the idea it's casting all these spells, by an alias. Obviously i have no idea how to invoke that table.

Thank you so muy, i'm a completly newbie in Lua, sadly.
Australia Forum Administrator #5
This looks like a cross-post of:

http://www.gammon.com.au/forum/?id=11722