RandomShovel

Run Programs From Disk

Jun 26th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. --[[  Variables  ]]--
  2.  
  3. local onDisk = {}
  4. local diskPresent = false
  5.  
  6.  
  7. --[[  Function  ]]--
  8.  
  9. local function load_programs()
  10.   local sides = peripheral.getNames()
  11.  
  12.   for a=1, #sides do
  13.     if peripheral.getType(sides[a]) == "drive" then
  14.       diskPresent = disk.hasData(sides[a])
  15.      
  16.       if diskPresent then
  17.         onDisk = fs.list("disk")
  18.       end
  19.       break
  20.     end
  21.   end
  22. end
  23.  
  24. local function run_program(prog)
  25.   if prog then
  26.     print("Running program \""..prog.."\"")
  27.     sleep(0.8)
  28.     shell.run("disk/"..prog)
  29.   end
  30. end
  31.  
  32. local function list_programs()
  33.   if diskPresent then
  34.     temp = {}
  35.     for a=1, #onDisk do
  36.       temp[tostring(a)] = onDisk[a]
  37.     end
  38.    
  39.     temp.clear()
  40.     term.setCursorPos(1, 1)
  41.     for a=1, #onDisk do
  42.       print(a..") "..temp[tostring(a)])
  43.     end
  44.    
  45.     write("Enter Program Number > ")
  46.     prog_number = read()
  47.    
  48.     if type(tonumber(prog_number)) == nil then
  49.       printError("That's not a valid number!")
  50.     else
  51.       run_program(temp[tostring(prog_number)])
  52.     end
  53.   else
  54.     printError("There are no programs in the floppy drive!")
  55.   end
  56. end
  57.  
  58.  
  59. --[[  Main  ]]--
  60.  
  61. load_programs()
  62. list_programs()
Advertisement
Add Comment
Please, Sign In to add comment