134 posts
Location
Salt Lake, UT
Posted 07 June 2012 - 04:27 PM
Can someone give me pointers or sourse code to making an e-mail system. I am working on a server like system inside minecraft and would like to save the e-mail(s) as a .txt file.
Questions:
1) can i do it?
2) can lua read and print the file name?
3) can lua read and print the contents?
THANKS!
436 posts
Posted 07 June 2012 - 04:50 PM
Take a look at the
fs api.
You kinda have to use the file name as a variable's contents to use it, and the contents are what that api is all about. Just, be sure you know how to work tables. And rednet. And how to make separate permissions. That last one should just take time, though.
146 posts
Location
the Netherlands
Posted 07 June 2012 - 06:52 PM
1. Yes, you can.
2.
rednet.receive()
to receive the file name, or make it inside of the message
3.
f = fs.open('newemail', 'r')
t = f.readAll()
f.close()
print(t)
92 posts
Posted 08 June 2012 - 02:15 AM
function receive()
local evt, id, msg = os.pullEvent("rednet_message")
newMail = fs.open("mail" .. mailNum, "w")
if newMail then
newMail.writeLine(msg)
newMail.close()
end
mailNum = mailNum + 1
end
shell.run("mkdir", "mail")
receive()
134 posts
Location
Salt Lake, UT
Posted 08 June 2012 - 02:57 AM
I'm still confused. what i will have it do is
x = io.read()
then i need to save x somehow… How would i do it and where would it end up? Then where do I tell the computer to read it? This is my ONLY problem. I got all the rest.
351 posts
Posted 08 June 2012 - 05:54 AM
I dont understand. Is the documentation for fs.open() too complicated?
134 posts
Location
Salt Lake, UT
Posted 08 June 2012 - 02:33 PM
Im having a hard time wrapping my head around it yes. Do you have any suggested material that i look at? (keep in mine youtube doesn't work at my house)
EDIT:
Just looked at the API thing again and I understand now. Thank you for your help
351 posts
Posted 08 June 2012 - 09:55 PM
The best thing to do when learning to use some programming language or library is to write small experimental test cases to clarify things.
92 posts
Posted 09 June 2012 - 01:34 AM
Here's a bit of code that should help you understand the filesystem API.
print("Please type what you want to be inside the file: ")
body = io.read()
print("Please type what you want the name of the file to be: ")
name = io.read()
file = fs.open(name, "w") --fs.open("test", type), will open file "test" or create it if it doesn't exist. "type" refers to the modes you can open a file in. Available open types are r (readonly), w (write. Note: Will clear the file of all contents. Same with 'wb'.), or a (append). The same commands are available in binary (rb, wb, ab)
if file then --To be honest I'm not too familiar with the fs API myself but I've always seen this in code so I've copied it.
file.writeLine(body) --Writes variable "body" to the file, if the variable contains and extremely long number or string, it will go on seperate lines.
file.close() --Make sure you close every file you open. Just do it.
end
134 posts
Location
Salt Lake, UT
Posted 09 June 2012 - 02:30 AM
Thanks