Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function load(name)
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function file_exists(name)
- local f=io.open(name,"r")
- if f~=nil then io.close(f) return true else return false end
- end
- oldnews = { }
- if file_exists("news") == false then
- save(oldnews, "news")
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.blue)
- write("Write new News:")
- news = read()
- if news == "delete" then
- term.clear()
- term.setCursorPos(1,1)
- write("Which number you want to delete?")
- oldnews = load("news")
- for i = 1, tablelength(oldnews) do
- term.setCursorPos(1,2+i)
- print(i .. ": ".. oldnews[i])
- end
- number = read()
- table.remove(oldnews, tonumber(number))
- save(oldnews, "news")
- else
- oldnews = load("news")
- table.insert(oldnews,".".. news .. "/n")
- save(oldnews, "news")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment