Advertisement
EmidioMata

StorageAntena

Jul 24th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. local storage
  2.  
  3.  
  4. function createsettings()
  5. local settings={}
  6. print("Number of Storage:")
  7. settings[1]="s"..read()
  8. save(settings,"settings.txt")
  9. end
  10.  
  11. function loadsettings()
  12. local settings=load("settings.txt")
  13. storage=settings[1]
  14. end
  15.  
  16. function save(table,name)
  17. local file = fs.open(name,"w")
  18. file.write(textutils.serialize(table))
  19. file.close()
  20. end
  21.  
  22. function load(name)
  23. local file = fs.open(name,"r")
  24. local data = file.readAll()
  25. file.close()
  26. return textutils.unserialize(data)
  27. end
  28.  
  29. function exist(name)
  30. file=io.open(name)
  31. if file~=nil then io.close(file) return true else return false end
  32. end
  33.  
  34. -----------------------------
  35. redstone.setOutput("bottom",false)
  36. if not exist("settings.txt") then
  37. createsettings()
  38. end
  39.  
  40. loadsettings()
  41. rednet.open("back")
  42.  
  43. if exist("changes") then redstone.setOutput("bottom",true) end
  44.  
  45. while true do
  46. local id, mens, protocol =rednet.receive()
  47. if protocol =="changesAntena"..storage then
  48. local changes={" "}
  49. if exist("changes") then
  50. changes=load("changes")
  51. end
  52. local newchanges=textutils.unserialize(mens)
  53. for i=1,#newchanges do
  54. changes[#changes+1]=newchanges[i]
  55. end
  56. save(changes,"changes")
  57. redstone.setOutput("bottom",true)
  58. rednet.send(id,"ok","changesAntenaReceived"..storage)
  59. end
  60. if protocol=="AskChangesAntena"..storage then
  61. local changes={" "}
  62. if exist("changes") then
  63. changes=load("changes")
  64. end
  65. rednet.send(id,textutils.serialize(changes),"changes"..storage)
  66. fs.delete("changes")
  67. redstone.setOutput("bottom",false)
  68. end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement