GraySloth

ComputerCraft: 'monStartup' runs a program to monitor start

Feb 6th, 2013
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. --v2.3 by GraySloth 2013-Apr-30
  2. --name this startup to run program on monitor automatically
  3. --Works great for this program but can be used for othes: http://pastebin.com/UkzR2J5T
  4. --variables
  5. local sSide = nil -- the side the monitor is on, nil will dynamically find the side but you can change it to be static
  6. local sProgram = { "clock" } -- the program you are running, now supports multiple arguments
  7. local textScale = 1 --change from 0.5 to 5
  8.    
  9.      --main
  10. if sSide == nil then
  11.    for n,sMonitorSide in ipairs(rs.getSides()) do
  12.     if peripheral.isPresent(sMonitorSide) and peripheral.getType(sMonitorSide) == "monitor" then
  13.        sSide = sMonitorSide
  14.        break
  15.     end
  16.    end
  17.  
  18.        
  19. if not sSide then
  20.    print( "No monitor attached" )
  21.   return
  22. end
  23. end
  24.  
  25.    
  26. if peripheral.getType( sSide ) ~= "monitor" then
  27.     print( "No monitor on "..sSide.." side" )
  28.     return
  29. end
  30.      
  31. local sPath = shell.resolveProgram( sProgram[1] )
  32. if sPath == nil then
  33.     print( "No such program: "..sProgram[1] )
  34.     return
  35. end
  36.  
  37. print( "Running "..sProgram[1].." on "..sSide.." monitor" )
  38.  
  39. local monitor = peripheral.wrap( sSide )
  40. monitor.setTextScale( textScale )
  41. term.redirect( monitor )
  42. shell.run( sProgram[1],sProgram[2], sProgram[3]  )
  43. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment