Advertisement
dexman545

Dialing Computer

Jan 21st, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. shell.run("pastebin", "get", "cXNuhwXh", "DexPI")
  2. shell.run("DexPI")
  3. clear(1,1)
  4. stargates = listPer("stargate")
  5. sg = peripheral.wrap(stargates[1])
  6. sgd = "sgDatabase"
  7.  
  8. function dWrite()
  9. local dbs = textutils.serialize(db)
  10. local file = fs.open(sgd, "w")
  11. file.write(dbs)
  12. file.close()
  13. end
  14.  
  15. function dRead()
  16. if fs.exists(sgd) then
  17. local file = fs.open(sgd, "r")
  18. db = textutils.unserialize(file.readAll())
  19. return db
  20. else
  21. return {}
  22. end
  23. end
  24. x, y = term.getSize()
  25.  
  26. paintutils.drawLine(1, 1, 51, 1, colors.gray)
  27. term.setBackgroundColor(colors.gray)
  28. function centered(text, l)
  29. term.setCursorPos((x/2) - (#text/2), l)
  30. write(text)
  31. local _,cy = term.getCursorPos()
  32. term.setCursorPos(1,cy + 1)
  33. end
  34. function header(text)
  35. term.setBackgroundColor(colors.gray)
  36. term.setTextColor(colors.blue)
  37. for i = 1, 2 do
  38. term.setCursorPos(1,i)
  39. write(string.rep(" ",x))
  40. end
  41. centered(text,1)
  42. term.setCursorPos(1,y)
  43. write(string.rep(" ",x))
  44. term.setBackgroundColor(colors.black)
  45. term.setTextColor(colors.white)
  46. term.setCursorPos(1,3)
  47. end
  48.  
  49. function add()
  50. header("Addition to Database")
  51. repeat
  52. write("Gate Serial: ")
  53. gser = read()
  54. until sg.isValidAddress(gser) == true
  55.  
  56. repeat
  57. print("\nDestination Name: ")
  58. gname = string.upper(read())
  59. until #gname > 2
  60.  
  61. db[gser] = {
  62. ["name"] = gname,
  63. }
  64. dWrite()
  65.  
  66. end
  67.  
  68.  
  69. header("Dialing Computer")
  70. db = dRead()
  71. add()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement