Guest User

startup

a guest
May 28th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. monitor = peripheral.wrap("right")
  2. monitor.clear()
  3. local Table = {}
  4. local function screenRefresh()
  5.   monitor.clear()
  6.   monitor.setCursorPos(1,1)
  7.   local x = 1
  8.   local y = 1
  9.   monitor.write("     THE GRAND TODO LIST!")
  10.   y=y+1
  11.  
  12.   monitor.setCursorPos(x,y)
  13.     for i = 1,#Table do
  14.        monitor.setCursorPos(x,y)
  15.        monitor.write(i..") "..Table[i])
  16.        y=y+1
  17.     end
  18. end
  19.  
  20.  
  21. function save(table,name)
  22.   local file = fs.open(name,"w")
  23.   file.write(textutils.serialize(table))
  24.   file.close()
  25. end
  26.  
  27. function load(name)
  28.   local file = fs.open(name,"r")
  29.   local data = file.readAll()
  30.   file.close()
  31.   return textutils.unserialize(data)
  32. end
  33.  
  34.  
  35.  
  36. local input = ""
  37. local numin = 0
  38. local taskin = ""
  39. while true do
  40.   screenRefresh()
  41.   print("What would you like to do?")
  42.   print("1) Add new item.")
  43.   print("2) Remove item.")
  44.   print("3) Refresh List.")
  45.   print("4) Restore Data.")
  46.  
  47.   input = read()
  48.   if (input == "1") and (#Table < 15) then
  49.     print("New Item:")
  50.     taskin = read()
  51.     table.insert(Table, taskin)
  52.     screenRefresh()
  53.     save(Table,"saved")  
  54.   elseif #Table > 15 then
  55.     print("Sorry, the list is full!")
  56.   end
  57.   if (input == "2") then
  58.     print("Which item should I remove?")
  59.     numin = tonumber(read())
  60.     if((numin ~= nil) and (numin <= #Table) and (numin >0)) then
  61.       table.remove(Table, numin)
  62.       save(Table,"saved")
  63.       screenRefresh()
  64.     else
  65.       print("That was not a number. Please Enter a number.")
  66.     end
  67.   end
  68.   if (input == "3") then
  69.     screenRefresh()
  70.   end
  71.   if(input == "4") then
  72.    Table = load("saved")
  73.     screenRefresh()  
  74.   end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment