meuced

parallel API

May 6th, 2013
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. function aff1()
  2.  
  3.     local i = 10
  4.     monl = peripheral.wrap("left")
  5.     local x1, y1 = monl.getSize()
  6.     local x, y
  7.    
  8.     for i=10, 1, -1 do
  9.         monl.write(i)
  10.         x, y = monl.getCursorPos()
  11.        
  12.         if y1 == y then
  13.             monl.scroll(1)
  14.             monl.setCursorPos(1, y)
  15.         else
  16.             monl.setCursorPos(1, y+1)
  17.         end
  18.         sleep(1)
  19.     end
  20.    
  21.     monl.write("fonction aff1 finie !")
  22.    
  23.     x, y = monl.getCursorPos()
  24.    
  25.     if y1 == y then
  26.         monl.scroll(1)
  27.         monl.setCursorPos(1, y)
  28.     else
  29.         monl.setCursorPos(1, y+1)
  30.     end
  31.    
  32. end
  33.  
  34.  
  35. function aff2()
  36.    
  37.     local i = 0
  38.     monr = peripheral.wrap("right")
  39.     local x1, y1 = monr.getSize()
  40.     local x, y
  41.    
  42.     for i=1, 7 do
  43.         monr.write(i)
  44.         x, y = monr.getCursorPos()
  45.        
  46.         if y1 == y then
  47.             monr.scroll(1)
  48.             monr.setCursorPos(1, y)
  49.         else
  50.             monr.setCursorPos(1, y+1)
  51.         end
  52.         sleep(1)
  53.     end
  54.    
  55.     monr.write("fonction aff2 finie !")
  56.    
  57.     x, y = monr.getCursorPos()
  58.    
  59.     if y1 == y then
  60.         monr.scroll(1)
  61.         monr.setCursorPos(1, y)
  62.     else
  63.         monr.setCursorPos(1, y+1)
  64.     end
  65.    
  66. end
  67.  
  68.  
  69. --**************************--
  70. --      Main Program        --
  71. --**************************--
  72.  
  73. -- waitForAny : stop a la 1ere fonction
  74. --     qui se termine
  75. parallel.waitForAny(aff1, aff2)
  76.  
  77. -- waitForAll : stop quand toutes les
  78. --     fonctions sont finies
  79. -- parallel.waitForAll(aff1, aff2)
  80.  
  81. monr.write("Programme fini !")
  82. monl.write("Programme fini !")
Advertisement
Add Comment
Please, Sign In to add comment