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, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ Checking for an empty variable fails?

Checking for an empty variable fails?

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


Posted by Winddancer   (26 posts)  Bio
Date Tue 07 Feb 2023 06:06 PM (UTC)

Amended on Tue 07 Feb 2023 06:28 PM (UTC) by Winddancer

Message
In my mud, a bard starts singing a song by using the command "singsong" plus a short name of the song, e.g. "singsong ranger" for singing a song about rangers.
To stop an ongoing song, you use the command "singsong" without a parameter.

I tried to write an alias that checks if %1 is empty and then sends "singsong" to the mud, without a parameter to stop the song and "singsong %1" in case I pass a songname to the alias.

Somehow the "singsong" without parameter never gets sent. When %1 is not empty, it works as intended. Any help?


<alias
   match="ss *"
   enabled="y"
   expand_variables="y"
   group="skalds"
   send_to="12"
   sequence="100"
  >
  <send>songWanted = string.lower ("%1")
if songWanted == '' then
  ColourNote ("#FFFF00", "", "End current song")
  Send("singsong")
  return
else
  ColourNote ("#FFFF00", "", "Sing song '" .. "%1" .. "'")
  Send("singsong %1")
end -- if

</send>
</alias>


Here is some sample output to illustrate the point(with command echo active):
Input: ss war
Output in game:
Sing song 'war'
singsong war - echo of command sent to the mud.
You start to sing 'Minstrelboy'.
You hum the melody of 'Minstrelboy'.
Input:
ss - echo of command sent to the mud.
Output in game:
What?
Top

Posted by Nick Gammon   Australia  (23,097 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 07 Feb 2023 08:24 PM (UTC)
Message
The trigger isn't matching because you are looking for "ss(space)" and typing "ss" on its own does not give the space.

There are various fixes, a simple one is to make two triggers, one matching on "ss *" and the other one matching on "ss".

Alternatively you can make a regular expression and match on: "^ss( .*)?$" which means the wildcard is now optional and it will still match on "ss". However now you have a leading space in the wildcard which you may want to remove (eg. by calling Trim).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Winddancer   (26 posts)  Bio
Date Reply #2 on Tue 07 Feb 2023 09:44 PM (UTC)
Message
Ahh... Thanks. Have overlook that tiny tidbit. *blush*
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.


4,069 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.