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

Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  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] Refresh page

Posted by Winddancer   (26 posts)  [Biography] bio
Date Tue 07 Feb 2023 06:06 PM (UTC)

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

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?

   match="ss *"
  <send>songWanted = string.lower ("%1")
if songWanted == '' then
  ColourNote ("#FFFF00", "", "End current song")
  ColourNote ("#FFFF00", "", "Sing song '" .. "%1" .. "'")
  Send("singsong %1")
end -- if


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'.
ss - echo of command sent to the mud.
Output in game:
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 07 Feb 2023 08:24 PM (UTC)
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
[Go to top] top

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


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.


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]