Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("right")
- local sFile = "MessageBoardLog.txt"
- local w, h = monitor.getSize()
- local sLog = {}
- function writeCenter(sString, yPos)
- x = math.floor((w / 2) - (#sString / 2))
- monitor.setCursorPos(x, yPos)
- monitor.write(sString)
- end
- function saveLog()
- local sFile = "MessageBoardLog.txt"
- if fs.exists(sFile) then
- local hRead = assert(fs.open(sFile, "r")) -- assert will error for us if we can't open the file.
- hRead.close() -- Close the handle! This is extremely important, as not doing so can cause errors when writin/opening the file.
- end
- hWrite = fs.open(sFile, "w") -- w for write! Note that this will also clear the file.
- hWrite.write(textutils.serialize(sLog))
- hWrite.close()
- return
- end
- function loadLog()
- if fs.exists(sFile) == true then
- local file = fs.open(sFile,"r")
- local data = file.readAll()
- file.close()
- sLog = textutils.unserialize(data)
- for i=1,#sLog do
- print(sLog[i])
- writeLine( sLog[i] )
- end
- else
- print("file does not exist, check path..")
- end
- end
- function addMessage()
- shell.run("clear")
- print ("Enter Message")
- local input = read()
- table.insert(sLog, input)
- writeLine(input)
- saveLog()
- end
- function writeLine(text)
- local _,row=monitor.getCursorPos()
- local _,height=monitor.getSize()
- --write the line
- monitor.write(text)
- --move to next row
- row=row+1
- --if this went off the screen, scroll
- --set to start of next line
- monitor.setCursorPos(1,row)
- end
- monitor.clear()
- loadLog()
- while true do
- addMessage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement