Advertisement
1amw31rd

ComputerCraft - Startup

Mar 7th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local program=""
  2. local args={}
  3. local autoRestart=true
  4.  
  5. -- Display ID
  6. shell.run("id")
  7.  
  8. -- Find a modem (from GPS script)
  9. for n,side in ipairs(rs.getSides()) do
  10.     if peripheral.getType(side) == "modem" then
  11.         rednet.open(side)
  12.         break
  13.     end
  14. end
  15.  
  16. -- Autorun program
  17. if program~=nil and program ~= "" then
  18.     if term.isColor() then
  19.         term.setTextColor(colors.yellow)
  20.         write("> ")
  21.         term.setTextColor(colors.white)
  22.     else
  23.         write("> ")
  24.     end
  25.    
  26.     print(program.." "..table.concat(args," "))
  27.  
  28.     if not shell.run(program, unpack(args)) then
  29.         if autoRestart then
  30.             write("'"..program.."' crashed! Restarting in ")
  31.             for i=5,1,-1 do
  32.                     write(i .. "...")
  33.                     sleep(1)
  34.                     local x, y = term.getCursorPos()
  35.                     term.setCursorPos(x-4, y)
  36.             end
  37.             term.clearLine()
  38.             local x, y = term.getCursorPos()
  39.             term.setCursorPos(1, y)
  40.             os.reboot()
  41.         else
  42.             print("'"..program.."' crashed!")
  43.         end
  44.     end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement