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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Appending date strings to saved notepads

Appending date strings to saved notepads

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


Posted by Balerion   (18 posts)  Bio
Date Tue 30 Jan 2007 05:24 PM (UTC)
Message
I've got some of the os calls out of the Sandbox, as directed elsewhere on the site, which I've been using to append a time stamp to pages that get directed to a notepad window. I'm thinking I'd like to keep daily logs of these things using SaveNotepad. My only problem is that I can't figure out how to give each file a unique name based on the day -- something like "my_notepad - 2006-01-30.txt" -- while using the SaveNotepad function. os.date doesn't seem to work inside the SaveNotepad function, and putting the desired timestring into a variable doesn't work as the Notepad just spits out the variable name (such as "t") rather than the variable content.

Is there any good way of doing this?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 30 Jan 2007 06:50 PM (UTC)
Message
I don't see why it wouldn't work, apart from coding errors. Can you please post your version, using os.date, that you say doesn't work?

- Nick Gammon

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

Posted by Balerion   (18 posts)  Bio
Date Reply #2 on Tue 30 Jan 2007 10:16 PM (UTC)
Message
Almost certainly it's my own mistake somewhere. I tried a number of things, but they're all variations of something like this:

t = os.date(%Y-%m-%d)
SaveNotepad("Game Log","c:/MUSH/MUSHclient/logs/Page Log - t.txt",0)

I'm guessing the problem is that I don't really understand how the os.date output gets put within the SaveNotepad function.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Tue 30 Jan 2007 11:02 PM (UTC)
Message
Oh. Lua has no idea that you're talking about the variable t and not the letter t. And that's a really good thing, actually -- otherwise it would replace the two t's in "txt" with your date!

Try:
SaveNotepad("Game Log","c:/MUSH/MUSHclient/logs/Page Log - " .. t .. ".txt",0)
instead. The .. operator is for string concatenation.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Balerion   (18 posts)  Bio
Date Reply #4 on Tue 30 Jan 2007 11:05 PM (UTC)
Message
Ah-ha. I hadn't quite understood what the .. .. thing meant before. Thanks. :)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 31 Jan 2007 03:23 AM (UTC)
Message
Also, os.date takes a string argument. Eg.


print (os.date(%Y-%m-%d)) --> Error: unexpected symbol near '%'

print (os.date("%Y-%m-%d")) --> 2007-01-31


- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


16,883 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.