print(os.date ("%c")) works with script prefix but alias doesn't.

Posted by Zack on Mon 26 Oct 2020 08:56 PM — 6 posts, 24,774 views.

#0
Hello.
I'm trying to get print(os.date ("%c")) working inside of an alias. My script prefix is / so when I'm in the normal window where I can send commands to the mud and I use / it works great. When I put print(os.date ("%c")) inside of the send field for the alias it gives me problems.
My goal is to have a trigger fire the alias or have the trigger directly use print(os.date ("%c but so far nothing is working.
the current alias...


<aliases>
  <alias
   match="time"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>print(os.date ("%c"))</send>
  </alias>
</aliases>


Error message...


Compile error
World: dw
Immediate execution
[string "Alias: "]:1: unfinished string near '"<aliases>'


Here's the error message from the trigger attempting to print.


Compile error
World: dw
Immediate execution
[string "Command line"]:1: '=' expected near '<eof>'


Thank you for your help!
Amended on Mon 26 Oct 2020 10:32 PM by Nick Gammon
Australia Forum Administrator #1
Inside an alias (and a trigger) "Send" box, the sequence %x where x is various letters and digits has a special meaning, as documented here:

http://www.gammon.com.au/scripts/doc.php?dialog=IDD_EDIT_ALIAS

In particular, %1 is the first wildcard, %2 the second wildcard, and so on. And, %c is the clipboard contents.

To pass "%c" down to Lua you need to double the % symbols, eg.


print(os.date ("%%c"))
Amended on Mon 26 Oct 2020 10:33 PM by Nick Gammon
USA Global Moderator #2
Quote:
Inside an alias

Inside a <send> </send> xml block, because it will happen for triggers too.
#3
Thank you so much Nick. I totally forgot about that being the norm. I use %1 all the time and it didn't even click in my brain that it was the issue.
I got it working now. Also thank you for making such an awesome accessible mud client! I love MC.
Australia Forum Administrator #4
Fiendish said:

Quote:
Inside an alias

Inside a <send> </send> xml block, because it will happen for triggers too.


Amended my reply to make that clearer.
Australia Forum Administrator #5
This happens more generally in trigger and alias "send" boxes, using send-to-script. For example, doing a string.match, and using %c to detect control characters would have a similar issue.

In those cases you should double the "%" symbols if you are using them other than for their intended purposes (wildcard 1, wildcard 2 etc.).

In fact, it is somewhat simpler in many ways to call a script function in your script file (and not use send-to-script) because functions inside your script file do not have these problems.