Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. function load(name)
  2.   local file = fs.open(name,"r")
  3.   local data = file.readAll()
  4.   file.close()
  5.   return textutils.unserialize(data)
  6. end
  7.  
  8. function save(table,name)
  9.   local file = fs.open(name,"w")
  10.   file.write(textutils.serialize(table))
  11.   file.close()
  12. end
  13.  
  14. function printTable(table)
  15.   if #table ~= 0 then
  16.     for i=1,#table do
  17.       print("Todo List:")
  18.       write(i)
  19.       write(" ")
  20.       print(table[i])
  21.     end
  22.   end
  23. end
  24.  
  25. function EditList()
  26.     print("Current List:")
  27.     printTable(table)
  28.     print("Enter the task to edit")
  29.     edit = io.read()
  30.     clrc()
  31.     write("Editing ")
  32.     print(edit)
  33.     print(table[edit])
  34.     table[edit] = io.read()
  35. end
  36.  
  37. function clrc()
  38.   term.clear()
  39.   term.setCursorPos(1,1)
  40. end
  41.  
  42. function Addtolist()
  43.     while input ~= "q" or "Q"do
  44.      clrc()
  45.      print("Adding to list (Enter q to Quit):\n")
  46.      write(count)
  47.      write(" ")
  48.      input = io.read()
  49.      if input ~= "q" or "Q" then
  50.        table[count] = input
  51.      end
  52.      count = count + 1
  53.     end
  54. end
  55.  
  56. clrc()
  57.  
  58. local table = {}
  59. local input = ""
  60. local edit
  61.  
  62. if fs.exists("list") then
  63.      table = load("list")
  64.      print("Existing List found.")
  65. end
  66.  
  67. local count = #table + 1
  68. local choice = 0
  69.  
  70. while choice ~= 4 do
  71.   clrc()
  72.   print("Todo List Program:")
  73.   print("1. Print Todo List")
  74.   print("2. Add to the List")
  75.   print("3. Edit part of List")
  76.   print("4. Quit")
  77.   input = io.read()
  78.   if input == 1 then
  79.     printTable()
  80.   end
  81.  if input == 2 then
  82.     Addtolist()
  83.   end
  84.   if input == 3 then
  85.     EditList()    
  86.   end
  87.   if input == 4 then
  88.     choice = 4
  89.   end
  90. end
  91.  
  92. clrc()
  93. save(table,"list")
  94. print("Todo List:")
  95. printTable(table)
  96. print("Program is not running:")
  97. print("Type todolist to run the program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement