Jameelo

To-do list

Nov 12th, 2022 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | Gaming | 0 0
  1. --[[
  2.     This is just to make sure I know how lua works lmao
  3.     It's a TODOLIST list, I can add stuff I need to do so I don't forget & stuff
  4.     To do file is called "toDoList"
  5. ]]
  6.  
  7. TODOLIST = {} --To do list in table form
  8. EXIT = false
  9. TODOSAVEfilename = "common/ToDoList"
  10.  
  11. os.loadAPI("common/systemLib.lua")
  12.  
  13. function addFunc()
  14.     --append to list
  15.     print("What would you like to add to the list?")
  16.     local task = string.lower(tostring(read()))
  17.     table.insert(TODOLIST,task)
  18.     systemLib.saveFile(TODOLIST,TODOSAVEfilename)
  19. end
  20.  
  21. function editFunc(taskIndex, newTask)
  22.     --change existing entry
  23.     print("What entry number do you want to edit?")
  24.     local index = tonumber(read())
  25.     print("And replace it with what?")
  26.     local answer = string.lower(tostring(read()))
  27.     TODOLIST[index] = answer
  28.     systemLib.saveFile(TODOLIST,TODOSAVEfilename)
  29.     lookFunc()
  30. end
  31.  
  32. function lookFunc()
  33.     --print list
  34.     term.clear()
  35.     for i,k in pairs(TODOLIST) do
  36.         print(i,k)
  37.     end
  38.     print("")
  39. end
  40.  
  41. function removeFunc()
  42.     --remove an entry
  43.     print("What entry number do you want to remove?")
  44.     local input = tonumber(read())
  45.     table.remove(TODOLIST,input)
  46.     systemLib.saveFile(TODOLIST,TODOSAVEfilename)
  47. end
  48.  
  49. local paths = {add = addFunc, edit = editFunc, remove = removeFunc} -- Function dictionary
  50.  
  51. if fs.exists(TODOSAVEfilename) then
  52.     TODOLIST = systemLib.loadFile(TODOSAVEfilename)
  53. else
  54.     TODOLIST = {"Make a to-do list!"}
  55.     systemLib.saveFile(TODOLIST, TODOSAVEfilename)
  56.     TODOLIST = systemLib.loadFile(TODOSAVEfilename)
  57. end
  58.  
  59. while EXIT == false do
  60.     lookFunc()
  61.     print("Would you like to do?")
  62.     print("Simply say: Add, Edit, or Remove")
  63.  
  64.     local uInput = string.lower(tostring(read()))
  65.     term.clear()
  66.  
  67.     if paths[uInput] ~= nil then
  68.         paths[uInput]()
  69.     elseif uInput == "exit" then
  70.         EXIT = true
  71.     else
  72.         print("Error, unrecognised function")
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment