Margresse404

fileReactorTryout

Jun 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. print("Changing settings for the reactor.")
  2. print("Current settings")
  3. fileName = "reactorSettings"
  4. local h
  5.  
  6. fileExists = fs.exists("disk/"..fileName)
  7.  
  8. function printContentsFile(file)
  9. nextLine = file.readLine()
  10. while nextLine ~= nil do
  11. print(nextLine)
  12. nextLine = file.readLine()
  13. end
  14. end
  15.  
  16. if fileExists then
  17. h = fs.open("disk/"..fileName, 'r')
  18. print("File exists! Contents:")
  19. printContentsFile(h)
  20. h.close()
  21. else
  22. print("Empty!")
  23. end
  24.  
  25. local cond = true
  26.  
  27. while cond == true do
  28. print("Do you want to overwrite or create a file? Y/N. (N exits the program)")
  29. answer = read()
  30.  
  31. if answer == "Y" then
  32. local cond2 = true
  33. h = fs.open("disk/"..fileName, 'w')
  34.  
  35. while cond2 == true do
  36.  
  37. print("Enter the number of a reactor. Enter -1 to exit adding reactors.")
  38. answer2 = read()
  39.  
  40. if answer2 == "-1" then
  41. print("Stopping file editing.")
  42. cond2 = false
  43. h.close()
  44. else
  45. h.writeLine(answer2)
  46. print("Reactor "..answer2.." written to file.")
  47. end
  48.  
  49. end
  50.  
  51. elseif answer == "N" then
  52. print("Ok, see you!")
  53. cond = false
  54. else
  55. print("Invalid input, try again.")
  56. end
  57.  
  58. end
Advertisement
Add Comment
Please, Sign In to add comment