Advertisement
MrkikouLIF

test coroutine 3

Oct 23rd, 2021
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function test1()  
  2.     while true do
  3.    
  4.         local event = {os.pullEvent("key")}
  5.    
  6.         if event[1] == "key" then    
  7.             term.setCursorPos(1,1)      
  8.             if event[2] == keys.enter then
  9.                 return true
  10.             end
  11.      
  12.             term.clearLine()
  13.             term.write(keys.getName(event[2]))
  14.         end  
  15.     end
  16. end
  17.  
  18.  
  19. local function test2()  
  20.     local lastEvt = os.clock()
  21.    
  22.     while true do  
  23.         local event = {os.pullEvent()}
  24.    
  25.         if event[1] == "key" then  
  26.             if not event[3] then  
  27.                 term.setCursorPos(1,2)
  28.                 term.clearLine()
  29.                 term.write(os.clock()-lastEvt.."s")
  30.                 lastEvt=os.clock()
  31.             end
  32.         end
  33.     end
  34. end  
  35.  
  36. local yolo1 = coroutine.create(test1)
  37. local yolo2 = coroutine.create(test2)
  38. local event = {}
  39.  
  40. while true do
  41.  
  42. --test1(term.current())
  43. --test2(term.current())
  44.  
  45. coroutine.resume(yolo1,unpack(event))
  46. coroutine.resume(yolo2,unpack(event))
  47.  
  48. if coroutine.status(yolo1) == "dead" or coroutine.status(yolo2) == "dead" then
  49.     break  
  50. end
  51.  
  52.  
  53. event = {os.pullEvent()}
  54. end
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement