Advertisement
Philipou

computercraft txt_to_monitor

Aug 19th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local function displayFile(file_name, hold_time, monitor_name)
  2.   -- count number of lines in the file
  3.   local lines = 0
  4.   for line in io.lines(file_name) do
  5.     lines = lines + 1
  6.   end
  7.  
  8.   parallel.waitForAny(
  9.     function()
  10.       -- run the editor
  11.       shell.run(string.format("monitor %s edit %s", monitor_name, file_name))
  12.     end,
  13.     function()
  14.       -- simulate a down key press every hold_time seconds
  15.       for i = 1, lines do
  16.         sleep(hold_time)
  17.         os.queueEvent("key", keys.down)
  18.       end
  19.     end
  20.   )
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement