Appending date strings to saved notepads

Posted by Balerion on Tue 30 Jan 2007 05:24 PM — 6 posts, 19,481 views.

#0
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?
Australia Forum Administrator #1
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?
#2
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.
USA #3
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.
#4
Ah-ha. I hadn't quite understood what the .. .. thing meant before. Thanks. :)
Australia Forum Administrator #5
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