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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Trigger; appending time of line
|
Trigger; appending time of line
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Wed 15 Mar 2006 12:29 AM (UTC) |
| Message
| | I have a trigger that matches on a string, and sends the string to a notepad window. Works fine, except I'd also like to append the time of the line that it was trigged on. Would I have to make it a script? What would I use for the time? |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Wed 15 Mar 2006 06:37 AM (UTC) |
| Message
| A small bit of scripting would to it. This example uses Lua as the script language, but other languages would have similar facilities:
<triggers>
<trigger
enabled="y"
match="^.*$"
regexp="y"
send_to="12"
sequence="100"
>
<send>AppendToNotepad ("mylog", "%0 " .. os.date ("%H:%M") .. "\\r\\n")
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #2 on Wed 15 Mar 2006 04:51 PM (UTC) Amended on Wed 15 Mar 2006 04:54 PM (UTC) by Zeno
|
| Message
| Hm, I'm getting an error. I match on this:
(With no regexp)
It sends:
AppendToNotepad ("AllSays", "%0 %1 said in room %2: %3" os.date ("%H:%M") "\r\n")
I get the error "Expected ')'".
Using commas, I get:
Cannot use parentheses when calling a Sub
|
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Wed 15 Mar 2006 07:56 PM (UTC) |
| Message
| This is VBscript, right? - judging by the error message.
In my Lua version I used ".." to concatenate strings. In VBscript you need to use "&" to do that. Also, in VBscript the date function isn't os.date - that is Lua.
You need to look in the VBscript manual for the function that converts the current time to printable. A possibility is simply:
Now ()
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #4 on Wed 15 Mar 2006 09:18 PM (UTC) |
| Message
| Whoops, forgot to change to Lua. If I try to just run this:
AppendToNotepad ("mylog", "test " .. os.date ("%H:%M") .. "\r\n")
I get this error:
Error number: 0
Event: Run-time error
Description: [string "Command line"]:1: attempt to index global `os' (a nil value)
stack traceback:
[string "Command line"]:1: in main chunk
Called by: Immediate execution
|
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Wed 15 Mar 2006 10:50 PM (UTC) |
| Message
| Later versions of MUSHclient have changed the default "Lua sandbox" in global preferences. Change the line:
to:
do
local a, b, c, d, e = os.date, os.time,
os.setlocale, os.clock, os.difftime
os = {} -- make new table
os.date, os.time, os.setlocale,
os.clock, os.difftime = a, b, c, d, e -- restore
end
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #6 on Wed 15 Mar 2006 10:52 PM (UTC) Amended on Wed 15 Mar 2006 10:53 PM (UTC) by David Haley
|
| Message
| You probably sand-boxed your scripts to remove the os table. I think this is the default, actually.
The sandboxing is in either global preferences or in the world preferences. You'll see something like:
os = nil
What you want to do is something like:
local os = os
os.date = _G.os.date
_G.os = nil
That should make your script work. If it doesn't, try:
local os_date = os.date
os = nil
Then, change your script to call os_date, not os.date.
(The first solution is somewhat more elegant, though, since you keep the os table, you just remove the stuff you don't like.)
EDIT: Or.... do what Nick said, posted while I was writing up mine. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #7 on Wed 15 Mar 2006 11:02 PM (UTC) Amended on Wed 15 Mar 2006 11:50 PM (UTC) by Zeno
|
| Message
| I did what Nick said:
loadlib = nil -- no loading DLLs
io = nil -- no disk IO
do
local a, b, c, d, e = os.date, os.time,
os.setlocale, os.clock, os.difftime
os = {} -- make new table
os.date, os.time, os.setlocale,
os.clock, os.difftime = a, b, c, d, e -- restore
end
Still get an error:
[string "Command line"]:1: attempt to index global `os' (a nil value)
stack traceback:
[string "Command line"]:1: in main chunk
Or do I have to restart MC?
[EDIT] Ah, I had to restart MC. *grunt* Had it open for 7 days. =P
I'm looking for docs on this date function, since I'd like to use month and day as well. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #8 on Thu 16 Mar 2006 12:36 AM (UTC) |
| Message
| Here you go:
http://www.lua.org/manual/5.0/manual.html#5.7
All the documentation for the os.xyz functions. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #9 on Thu 16 Mar 2006 12:45 AM (UTC) |
| Message
| | Thanks, although it's odd. Doesn't mention anything about %H or related things. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #10 on Thu 16 Mar 2006 01:25 AM (UTC) |
| Message
| | In that case it probably uses the standard formats, like in strftime or whatever the C function is called. In fact:
Quote: If format is not *t, then date returns the date as a string, formatted according to the same rules as the C function strftime. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #11 on Thu 16 Mar 2006 01:34 AM (UTC) |
| Message
| Thanks, now I got it.
AppendToNotepad ("AllSays", os.date ("%a %b %d %H:%M:%S %Y") .. " :: %1 said in room %2: %3\r\n")
|
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #12 on Thu 16 Mar 2006 04:18 AM (UTC) |
| Message
| Date formats are documented in the help file under the Lua "os" functions section, which is exactly the same as this page:
http://www.gammon.com.au/scripts/doc.php?general=lua_os
Quote:
Ah, I had to restart MC. *grunt* Had it open for 7 days.
Must be very reliable then *wink*.
As a matter of fact, reloading scripting would have done it. The sandbox is processed every time the script engine is instantiated. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zeno
USA (2,871 posts) Bio
|
| Date
| Reply #13 on Thu 16 Mar 2006 04:22 AM (UTC) Amended on Thu 16 Mar 2006 04:23 AM (UTC) by Zeno
|
| Message
| Ah, I glanced over your Lua docs but didn't see it.
Quote: Must be very reliable then *wink*.
Indeed. It takes a few minutes to open World Properties (300k lines+), but it rarely crashes. Actually I'm surprised Windows has stayed stable that long. =P |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | | 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.
33,534 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top