goreae

CC VOTE/UI/BALLOT

Jan 3rd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. function clearScreen()
  2.   term.clear()
  3.   term.setCursorPos(1,1)
  4. end
  5. local tArgs = {...}
  6. local command = tArgs[1]
  7. if command == "help" then
  8.   print("availiable commands are:")
  9.   print("  create-makes a new ballot.")
  10.   print("  delete-deletes a ballot.")
  11.   print("  info-displays info on a given ballot.")
  12.   print("  list-displays a list of all currect ballots.")
  13. end
  14. if command == "list" then
  15.   ballots = fs.list("disk")
  16.   for i = 1,1000 do
  17.     if ballots[i] == nil then break end
  18.     if ballots[i] ~= "idlists" then
  19.       if ballots[i] ~= "results" then
  20.         print(ballots[i])
  21.       end
  22.     end
  23.   end
  24. end
  25. if command == "info" then
  26.   print("What ballot would you like information on?")
  27.   ballot = read()
  28.   hrBallot = fs.open("disk/"..ballot,"r")
  29.   print("Information on "..ballot)
  30.   print(nil)
  31.   print(hrBallot.readLine())
  32.   print(nil)
  33.   print("Press any key to continue.")
  34.   os.pullEvent("key")
  35.   hrBallot.close()
  36. end
  37. if command == "create" then
  38.   clearScreen()
  39.   print("What would you like to name your ballot?")
  40.   name = read()
  41.   ballot = fs.open("disk/"..name,"w")
  42.   clearScreen()
  43.   print("Please explain the ballot for the voters:")
  44.   desc = read()
  45.   ballot.write(desc)
  46.   ballot.close()
  47.   hResults = fs.open("disk/results/"..name,"w")
  48.   tResults = {0,0}
  49.   hResults.writeLine(textutils.serialize(tResults))
  50.   hResults.close()
  51.   error()
  52. end
  53. if command == "delete" then
  54.   term.clear()
  55.   term.setCursorPos(1,1)
  56.   print("enter name of ballot to delete:")
  57.   local ballot = read()
  58.   while true do
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61.     print("Are you sure you want to delete ballot '"..ballot.."'? This cannot be undone. (type yes or no.)")
  62.     local choice = read()
  63.     if choice == "yes" then
  64.       fs.delete("disk/"..ballot)
  65.       fs.delete("disk/idlists/"..ballot)
  66.       print("Ballot '"..ballot.."' deleted.")
  67.       break
  68.     else
  69.       if choice == "no" then
  70.         break
  71.       else
  72.         term.clear()
  73.         term.setCursorPos(1,1)
  74.         print("'"..choice.."' is not a valid option. Please type yes or no.")
  75.         sleep(2)
  76.       end
  77.     end
  78.   end
  79. error()
  80. end
Advertisement
Add Comment
Please, Sign In to add comment