Posted 07 April 2015 - 04:09 AM
Hi all,
I can not find how to do this anywhere, so I've decided to ask here. My code is meant to be a journal of sorts, where you can create and access logs. I wish to stop writing to the log after the ENTER key is pressed, but I've no idea how.
Here is the code in question:
I assume this means it is trying to index the enter key, which is why I wish to filter out the enter key from being written to the file. I assume it would be along the lines of
Thanks in advance!
I can not find how to do this anywhere, so I've decided to ask here. My code is meant to be a journal of sorts, where you can create and access logs. I wish to stop writing to the log after the ENTER key is pressed, but I've no idea how.
Here is the code in question:
done = false
print("1. Read log")
print("2. Create log")
print("3. List logs")
print("4. Exit")
while true do
event, key = os.pullEvent("char")
if key == "1" then
print("Enter log name:")
sFile = read()
print(file.read("logs/"..sFile, "a"))
return
elseif key =="2" then
print("Log Name:")
sFile = read()
print("Input ENTER to finish.")
repeat
input = read()
file.write("logs/"..sFile, "w", input) --attempt to index ? (a nil value)
until done
return
elseif key == "3" then
shell.run("list", "logs")
return
elseif key == "4" then
shell.run("load")
else then
print("ERROR: Command not recognized")
end
end
The returned error is:
logs:28: attempt to index ? (a nil value)
I assume this means it is trying to index the enter key, which is why I wish to filter out the enter key from being written to the file. I assume it would be along the lines of
if input == key28 then --key28 being Minecraft's enter key id
...
but this will not work. For this reason I turn to you; how is this done?Thanks in advance!
Edited on 07 April 2015 - 03:42 PM