Advertisement
BigSHinyToys

Computer Craft movie player

Dec 20th, 2012
3,601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. --[[
  2.         remote Movie controll
  3.         by BigSHinyToys
  4. ]]--
  5.  
  6. local function openDevice(sType)
  7.     for i,v in pairs(rs.getSides()) do
  8.         if peripheral.isPresent(v) and peripheral.getType(v) == sType then
  9.             return peripheral.wrap(v),v
  10.         end
  11.     end
  12. end
  13.  
  14. local _notused,monSide = openDevice("monitor")
  15. local _notused,wifiSide = openDevice("modem")
  16.  
  17. if not monSide then
  18.     error("No monitor Connected")
  19. end
  20. if wifiSide then
  21.     rednet.open(wifiSide)
  22. else
  23.     error("No wifi modem")
  24. end
  25. term.redirect(peripheral.wrap(monSide))
  26.  
  27. local function newMovie()
  28.     return coroutine.create(function() os.run({},"/rom/programs/secret/alongtimeago") end)
  29. end
  30.  
  31. local movie = newMovie()
  32. local keepPlaying = false
  33. local lastEvent
  34.  
  35.  
  36. while true do
  37.     local event = {os.pullEventRaw()}
  38.     if event[1] == "rednet_message" then
  39.         if event[3] == "play" then
  40.             keepPlaying = true
  41.             event = lastEvent or {}
  42.         elseif event[3] == "pause" then
  43.             keepPlaying = false
  44.         elseif event[3] == "newFilm" then
  45.             movie = newMovie()
  46.             keepPlaying = false
  47.             term.clear()
  48.         elseif event[3] == "clear" then
  49.             term.clear()
  50.         elseif event[3] == "pingMovie" then
  51.             rednet.send(event[2],"IamMovie")
  52.         end
  53.     elseif event[1] == "timer" then
  54.         lastEvent = event
  55.     elseif event[1] == "terminate" then
  56.         term.clear()
  57.         term.restore()
  58.         error()
  59.     end
  60.     if keepPlaying then
  61.         coroutine.resume(movie,unpack(event))
  62.     end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement