Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tTodoList = {}
- local saveFile = "disk/todo"
- local function addToList(todo)
- table.insert( tTodList, todo)
- local q = fs.open( saveFile, "w")
- q.write( textutils.serialize(tTodoList))
- q.close()
- end
- local function readFromFile()
- local a = fs.open( saveFile, "r")
- tTodoList = textutils.unserialize( a.readAll( "*a"))
- a.close()
- end
- local function writeToFile()
- local b = fs.open( saveFile, "w")
- b.write(textutils.serialize( tTodoList ))
- b.close()
- end
- local function removeFromList(todo)
- if type(todo) == "number" then
- table.remove( tTodoList, todo)
- elseif type(todo) == "string" then
- if tonumber( todo ) then
- table.remove(tTodoList, todo)
- else
- for i = 1, #tTodoList do
- if tTodoList[i] == todo then
- table.remove( tTodoList, i )
- break
- end
- end
- end
- else
- return false
- end
- writeToFile()
- return true
- end
- local function checkList( id )
- rednet.send( id, textutils.serialize( tTodoList))
- end
- rednet.open("top")
- readFromFile()
- while true do
- local id, cmd = rednet.receive()
- if cmd == "create" then
- print("Add: "..id)
- rednet.send(id, "What would you like to add?")
- idb, txtb = rednet.receive()
- print(txtb)
- print("------------------------")
- addToList(txtb)
- elseif cmd == "delete" then
- print("Delete: "..id)
- rednet.send(idb, "What would you like to delete?")
- ida, txta = rednet.receive()
- print(txta)
- print("----------------------")
- if not removeFromList(txta) then
- print(" Failed: Does not Exist.")
- end
- elseif cmd == "read" then
- print("Read: "..id)
- print("------------------------")
- checkList(ida)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment