Advertisement
Rolcam

Computercraft/Computronics Tape DJ Program - Stop

Sep 4th, 2023 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. args = {...}
  2. mon = peripheral.wrap("monitor_0")
  3. ter = term.current()
  4. -- the taper variables are the names/side of each drive. Since they are called multiple times, I am using variables to set them so it is easier to rename them
  5. taper1 = "tape_drive_3"
  6. taper2 = "tape_drive_4"
  7. taper3 = "tape_drive_5"
  8.  
  9. -- Stops the tape and rewinds it if the "hot" parameter is not used when calling the program
  10. function rewinder()
  11.     term.redirect(mon)
  12.     term.setTextColor(colors.red)
  13.     print("Stopped:")
  14.     print(tape.getLabel())
  15.     term.redirect(ter)
  16.     if args[2] == nil then
  17.         if tape == nil then
  18.             sleep(0.1)
  19.         else
  20.             tape.seek(-tape.getSize())
  21.         end
  22.     elseif args[2] == "hot" then
  23.         term.setTextColor(colors.orange)
  24.         print("hot parameter used! Not rewinding the tape!")
  25.         term.setTextColor(colors.white)
  26.     else
  27.         term.setTextColor(colors.red)
  28.         print("Parameter 2 Invalid! Using Default Value...")
  29.         term.setTextColor(colors.white)
  30.         tape.seek(-tape.getSize())
  31.     end
  32.     if tape == nil then
  33.         sleep(0.1)
  34.     else
  35.         tape.stop()
  36.     end
  37. end
  38.  
  39.  
  40. if args == nil then
  41. term.setTextColor(colors.red)
  42. print("Warning: No parameters given!")
  43. print("Use \"stop #\" to select a drive")
  44. else
  45.     if args[1] == "1" then
  46.         print("Stopping Drive 1")
  47.         tape = peripheral.wrap(taper1)
  48.         rewinder()
  49.     elseif args[1] == "2" then
  50.         print("Stopping Drive 2")
  51.         tape = peripheral.wrap(taper2)
  52.         rewinder()
  53.     elseif args[1] == "3" then
  54.         print("Stopping Drive 3")
  55.         tape = peripheral.wrap(taper3)
  56.         rewinder()
  57.     elseif args[1] == "all" then
  58.         print("Stopping all tape drives...")
  59.         print("Stopping Drive 1")
  60.         tape = peripheral.wrap(taper1)
  61.         rewinder()
  62.         print("Stopping Drive 2")
  63.         tape = peripheral.wrap(taper2)
  64.         rewinder()
  65.         print("Stopping Drive 3")
  66.         tape = peripheral.wrap(taper3)
  67.         rewinder()
  68.         print("All tape drives were stopped!")
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement