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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Compare variables

Compare variables

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


Posted by Winddancer   (26 posts)  [Biography] 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?
[Go to top] top

Posted by Fiendish   USA  (2,513 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] 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
[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.


2,286 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at HostDash]