FireDemonite icon

Message Board

FireDemonite | PRO | 11/03/18 06:25:30 PM UTC | 0 ⭐ | 160 👁️ | Never ⏰ | []
Lua |

1.67 KB

|

None

|

0 👍

/

0 👎

local mon = peripheral.wrap("top")
local currPos = 0
local Messages = {}
 
mon.setTextScale(0.5)
 
if (fs.exists(".config")) then
    local file = fs.open(".config","r")
    Messages = textutils.unserialise(file.readAll())
    file.close()
else
    local file = fs.open(".config","a")
    file.close()
end
 
while true do
    mon.clear()
    mon.setCursorPos(1,1)
    for i = 1,#Messages do
        x,y = mon.getCursorPos()
        mon.setCursorPos(1, y+1)
        mon.write(tonumber(i).." ")
        --mon.setCursorPos(2, y+1)
        msg = Messages[i]
        --print(string.len(msg))
        --sleep(2)
        while string.len(msg) > 13 do
            mon.write(string.sub(msg, 1, 13))
            msg = string.sub(msg, 14)
            x,y = mon.getCursorPos()
            mon.setCursorPos(3, y+1)
        end
        mon.write(msg)
        --mon.write(Messages[i])
    end
    term.clear()
    term.setCursorPos(1,1)
    print("MESSAGE BOARD")
    term.write("# ")
    command = read()
    if (command == "add") then
        --term.clear()
        --term.setCursorPos(1,1)
        term.write(": ")
        addMessage = read()
        table.insert(Messages, addMessage)
        local file = fs.open(".config","w")
        file.write(textutils.serialise(Messages))
        file.close()
    elseif (command == "remove") then
        term.write(": ")
        rmMessage = read()
        table.remove(Messages,tonumber(rmMessage))
        local file = fs.open(".config","w")
        file.write(textutils.serialise(Messages))
        file.close()
    elseif (command == "help") then
        print("add")
        print("remove")
        sleep(2)
    end
end

Comments