Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ Compare variables

Compare variables

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Winddancer   (26 posts)  Bio
Date Fri 26 May 2023 05:06 PM (UTC)
Message
I want to execute a command, depending on the value of a variable.

I probably am missing something here, as the following does not work:


  <alias
   match="v_sslam"
   enabled="y"
   expand_variables="y"
   group="specials"
   send_to="12"
   omit_from_output="y"
   sequence="100"
  >
  <send>Note ("inside " .. "@myspecialname")
Send("slam")
Send("@myelbow")
Send("knee")
Send("headbutt")
if @punch_attack == 'yes' then
  Send("punch")
end
Send("kick")
</send>


Regardless wether the variable has the value yes or no, the command punch is not sent.

When I change the alias to:

  <alias
   match="v_sslam"
   enabled="y"
   expand_variables="y"
   group="specials"
   send_to="12"
   omit_from_output="y"
   sequence="100"
  >
  <send>Note ("inside " .. "@myspecialname")
Send("slam")
Send("@myelbow")
Send("knee")
Send("headbutt")
if @punch_attack == yes then
  Send("punch")
end
Send("kick")
</send>


Regardless wether the variable has the value yes or no, the command punch is sent.

What am I doing wrong? What am I missing?
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #1 on Fri 26 May 2023 05:50 PM (UTC)

Amended on Fri 26 May 2023 05:58 PM (UTC) by Fiendish

Message
Missing quotation marks.

Try this instead

 <alias
   match="v_sslam"
   enabled="y"
   expand_variables="y"
   group="specials"
   send_to="12"
   omit_from_output="y"
   sequence="100"
  >
  <send>
Note("inside @myspecialname")
Send("slam")
Send("@myelbow")
Send("knee")
Send("headbutt")
if "@punch_attack" == "yes" then
  Send("punch")
end
Send("kick")
</send>



Side note:

I always advise people that using expand_variables-style "@" notation inside the send block is a dangerous idea that everyone should get out of the habit of doing because it will at some point cause a problem.

@whatever gets set via find/replace before the code gets sent to the script engine, so anything you might set inside the code itself will not get picked up. In this specific case you're fine, but people usually don't realize this difference and then get stuck wondering why something a little more complex doesn't pick up the variables they just set.

I think everyone should get used to using SetVariable/GetVariable instead when inside a script section (send_to="12") and only use "@" expansion in match patterns (when you need an alias to match a pattern based on some variable that is set).

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 31 May 2023 06:11 AM (UTC)

Amended on Wed 31 May 2023 06:12 AM (UTC) by Nick Gammon

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


There might be other useful tips for you on that page as well. In your case it wasn't a wildcard, but the concept is the same.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


3,854 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.