Advertisement
domi02198

[ComputerCraft] Chat Program v 2.1

Aug 27th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. m = peripheral.wrap("right")
  2. function Mprint(txt)
  3.     color = 2^math.random(1,16)
  4.     term.setTextColor(color)
  5.     print(txt)
  6.     term.setTextColor(colors.white)
  7.  
  8. end
  9. function Mwrite(txt)
  10.     color = 2^math.random(1,16)
  11.     term.setTextColor(color)
  12.     write(txt)
  13.     term.setTextColor(colors.white)
  14.  
  15. end
  16.  
  17.  
  18. while true do
  19.     h = fs.open("chat.txt","r")
  20.     name = textutils.unserialize(h.readLine())
  21.     msg =  textutils.unserialize(h.readLine())
  22.     h.close()
  23.     term.redirect(m)
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     for i= 1,#name do
  27.         Mwrite(name[i]..": ")
  28.         Mprint(msg[i])
  29.        
  30.     end
  31.     term.restore()
  32.     term.clear()
  33.     term.setCursorPos(1,5)
  34.     Mprint("Name: "
  35.     n= read()
  36.     Mprint("\n\nText:")
  37.     m = read()
  38.     fs.delete("chat.txt")
  39.     h = fs.open("chat.txt","w")
  40.     table.insert(name,n)
  41.     table.insert(msg,m)
  42.     h.writeLine(textutils.serialize(name))
  43.     h.writeLine(textutils.serialize(msg))
  44.     h.close()
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement