chopstyix

cPhone

Dec 31st, 2020 (edited)
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. os.loadAPI("UI")
  2. local monX, monY = term.getSize()
  3.  
  4. TURTLEPORT = 69 -- nice
  5. CPHONEPORT = 70
  6. local modem = peripheral.wrap("back")
  7. modem.open(CPHONEPORT)
  8.  
  9. local function relay()
  10.     local input
  11.     input = read()
  12.     local message = string.lower(input)
  13.     modem.transmit(TURTLEPORT,CPHONEPORT,message)
  14.     print("Sending...")
  15. end
  16.  
  17. local function listen()
  18.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  19.     if senderChannel == CPHONEPORT then
  20.         -- Send message from turtle to cPhone
  21.         print(message)
  22.         return message
  23.     end
  24. end
  25.  
  26. local function relayMessage(str)
  27.     local message = string.lower(str)
  28.     modem.transmit(TURTLEPORT,CPHONEPORT,message)
  29. end
  30.  
  31. io.write("Booting cPhone")
  32. for i=1,3 do
  33.     io.write(".")
  34.     os.sleep(1)
  35. end
  36. shell.run("clear")
  37.  
  38. -- while true do
  39. --     parallel.waitForAny(listen,relay)
  40. -- end
  41.  
  42. -- Function that requests a message from all active turtles in the network
  43. -- local function turtleSignal()
  44.    
  45.  
  46. headerText = UI.Widget:new()
  47. headerText.label = "turtleNet"
  48. headerText.x = math.ceil((monX / 2) - (headerText.label:len() / 2))
  49. headerText.y = 1
  50.  
  51. connectButton = UI.Widget:new()
  52. connectButton.label = "CONNECT"
  53. connectButton.x = math.ceil((monX / 2) - (headerText.label:len() / 2))
  54. connectButton.y = 4
  55. connectButton.key = 30
  56. connectButton.fontColor = 1
  57. connectButton.backgroundColor = 64
  58. connectButton.onClick = function (self) -- When the user clicks on this button it will do something
  59.     modem.transmit(TURTLEPORT,CPHONEPORT,"rollCall")
  60. end
  61. -- connectButton.tick = function (self) -- Every tick this updates
  62.  
  63. turtleInfo = UI.Widget:new()
  64. turtleInfo.label = "test" -- Turtle Name
  65. turtleInfo.x = 1
  66. turtleInfo.y = 5
  67.  
  68. vp = UI.Viewport:new()
  69. vp:addWidget(headerText)
  70. vp:addWidget(connectButton)
  71.  
  72. app = UI.App:new()
  73. app:setViewport(vp)
  74. app:run()
  75.  
  76. -- farmButton = UI.Widget:new()
  77. -- farmButton.x = 12
  78. -- farmButton.y = 6
  79. -- farmButton.farmWidth = 1
  80. -- farmButton.farmDepth = 1
  81. -- farmButton.label = "Launch farming"
  82. -- farmButton.backgroundColor = 2048
  83. -- farmButton.fontColor = 1
  84. -- farmButton.onClick = function (self)
  85. --  term.clear()
  86. --  term.setCursorPos(1,1)
  87. --  os.sleep(3)
  88. -- end
  89.  
  90. -- refuelButton = UI.Widget:new()
  91. -- refuelButton.x = 10
  92. -- refuelButton.y = 8
  93. -- refuelButton.label = "Refuel"
  94. -- refuelButton.backgroundColor = 2048
  95. -- refuelButton.fontColor = 1
  96. -- refuelButton.onClick = function (self)
  97. --  print("test")
  98. -- end
  99.  
  100. -- fuelText = UI.Widget:new()
  101. -- fuelText.x = 10
  102. -- fuelText.y = 10
  103. -- fuelText.label = "Fuel level : "
  104.  
  105. -- fuelLevel = UI.Widget:new()
  106. -- fuelLevel.x = 22
  107. -- fuelLevel.y = 10
  108. -- fuelLevel.label = test
  109. -- fuelLevel.tick = function(self)
  110. --  self.label = "test"
  111. -- end
  112.  
  113. -- vp = UI.Viewport:new()
  114. -- vp:addWidget(farmButton)
  115. -- vp:addWidget(refuelButton)
  116. -- vp:addWidget(fuelText)
  117. -- vp:addWidget(fuelLevel)
  118.  
  119. -- app = UI.App:new()
  120. -- app:setViewport(vp)
  121. -- app:run()
  122.  
  123. -- -- Initialize cPhone
  124. -- TURTLEPORT = 69 -- nice
  125. -- CPHONEPORT = 70
  126. -- local modem = peripheral.wrap("back")
  127. -- --modem.open(TURTLEPORT)
  128. -- modem.open(CPHONEPORT)
  129.  
  130. -- print("Booting cPhone")
  131. -- local function listen()
  132. --     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  133. --     if senderChannel == CPHONEPORT then
  134. --         -- Send message from turtle to cPhone
  135. --         print(message)  
  136. --     end
  137. -- end
  138.  
  139. -- local function relay()
  140. --     local input
  141. --     input = read()
  142. --     local message = string.lower(input)
  143. --     modem.transmit(TURTLEPORT,CPHONEPORT,message)
  144. --     print("Sending...")
  145. -- end
  146.  
  147. -- while true do
  148. --     parallel.waitForAny(listen,relay)
  149. -- end
Add Comment
Please, Sign In to add comment