Advertisement
Redxone

Chat Test - BUGGY

Jul 7th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. modem = peripheral.find("modem")
  2.  
  3. local mtable = {}
  4. local w, h = term.getSize()
  5.  
  6. os.loadAPI("ea")
  7.  
  8. function clear()
  9.  
  10.         ea.sbc(colors.white)
  11.         term.clear()
  12.  
  13.         ea.stc(colors.blue)
  14.         ea.scp(1,18)
  15.         ea.sbc(colors.gray)
  16.         write("<Type /help for help>")
  17.         ea.sbc(colors.white)
  18.  ea.scp(1,19)
  19.         write("[::> ")
  20.         ea.scp(6,19)
  21.  
  22. end
  23.  
  24.  
  25. function start()
  26.  
  27.         ea.sbc(colors.white)
  28.  ea.stc(colors.black)
  29.         term.clear()
  30.         ea.scp(16,9)
  31.         print("Kosy Chat System")
  32.         ea.scp(13,11)
  33.         print("Username: ")
  34.         ea.scp(13,12)
  35.         print("Channel : ")
  36.  
  37.         ea.scp(22,11)
  38.         us = io.read()
  39.         ea.scp(22,12)
  40.         ch = io.read()
  41.  
  42.         modem.open(tonumber(ch))
  43.         clear()
  44.         chatgo()
  45.  
  46. end
  47.  
  48.  
  49.  
  50. function drawm()
  51.  
  52.         if(#mtable > h-2)then local tt = mtable[h-2] mtable = {} table.insert(mtable,tt) tt = "" end
  53.  
  54.         for i = 1, #mtable do
  55.  
  56.                 ea.scp(1,i)
  57.   print(mtable[i])
  58.  
  59.         end
  60.  
  61. end
  62.  
  63.  
  64. function receive()
  65.  
  66.         e = {os.pullEvent("modem_message")}
  67.  
  68.  
  69.                  table.insert(mtable, e[5])
  70.  
  71.  end
  72.  
  73.  function send()
  74.  
  75.  
  76.    
  77.                 ea.scp(7,19)
  78.                 readm = read()
  79.                 modem.transmit(tonumber(ch), tonumber(ch), "<"..us..">: "..readm)
  80.                 table.insert(mtable,"me > "..readm)
  81.                 clear()
  82.  
  83.      
  84.  
  85. end
  86.  
  87.  
  88. function chatgo()
  89.  
  90.         while true do
  91.  
  92.                 drawm()
  93.                 parallel.waitForAny(send, receive)
  94.  
  95.         end
  96.  
  97. end
  98. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement