Checking for an empty variable fails?

Posted by Winddancer on Tue 07 Feb 2023 06:06 PM — 3 posts, 9,023 views.

#0
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?
Amended on Tue 07 Feb 2023 06:28 PM by Winddancer
Australia Forum Administrator #1
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).
#2
Ahh... Thanks. Have overlook that tiny tidbit. *blush*