LivioBrunner

Main Computer

Nov 17th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. color = { 0 }
  2. name = { 0 }
  3. ids = { 59 }
  4. function tclear(x,y)
  5.     if x == nil then
  6.         x = 1
  7.     end
  8.     if y == nil then
  9.         y = 1
  10.     end
  11.     term.clear()
  12.     term.setCursorPos(x,y)
  13. end
  14. function tablelength(T)
  15.   local count = 0
  16.   for _ in pairs(T) do count = count + 1 end
  17.   return count
  18. end
  19. function load(name)
  20.     local file = fs.open(name,"r")
  21.     local data = file.readAll()
  22.     file.close()
  23.     return textutils.unserialize(data)
  24. end
  25. function save(table,name)
  26.     local file = fs.open(name,"w")
  27.     file.write(textutils.serialize(table))
  28.     file.close()
  29. end
  30. -------------FUNCTIONS
  31.  
  32.  
  33.  
  34.  
  35. tclear()
  36. fs.makeDir("saves")
  37. if fs.exists("saves/colors") ~= true then
  38.     save(color,"saves/colors")
  39.     save(name, "saves/name")
  40. end
  41. rednet.open("right")
  42. for i = 1, tablelength(ids) do
  43.         print(color)
  44.         rednet.send(ids[i], color)
  45.         rednet.send(ids[i], name)
  46. end
  47. while true do
  48.     color = load("saves/colors")
  49.     name = load("saves/name")
  50.     for i = 1, tablelength(ids) do
  51.         rednet.send(ids[i], color)
  52.         rednet.send(ids[i], name)
  53.     end
  54.     local senderId, message, distance = rednet.receive()
  55.     if string.find(message, "color", 1) ~= nil then
  56.        
  57.         message = string.sub(message,6,string.len(message))
  58.         table.insert(color, message)
  59.         save(color, "saves/colors")
  60.     else
  61.        
  62.         table.insert(name, message)
  63.         save(name, "saves/name")
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment