daily pastebin goal
16%
SHARE
TWEET

Quarry Receiver 3.4.0

civilwargeeky Jan 20th, 2014 1,106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Quarry Receiver Version 3.4.0
  2. --Made by Civilwargeeky
  3. --[[
  4. Ideas:
  5. For session persistence, you probably only need to save what monitor and what turtle to connect with.
  6. ]]
  7. --[[
  8. Recent Changes:
  9.   Made from scratch!
  10. ]]
  11.  
  12. local debug = false
  13. local sloppyHandshake = true --If receiver can pick back up in the middle w/o handshake
  14. local defaultCheckScreen = false --If this is true, it will automatically check for a screen around it.
  15.  
  16. local mon, modem, sendChannel, receiveChannel, isDone
  17. local currBackgroundColor = colors.black
  18. local currTextColor = colors.white
  19. local function setTextColor(color)
  20.   if mon.isColor() then
  21.     currTextColor = color
  22.     return mon.setTextColor(color)
  23.   end
  24. end
  25. local function setBackgroundColor(color)
  26.   if mon.isColor() then
  27.     currBackgroundColor = color
  28.     return mon.setBackgroundColor(color)
  29.   end
  30. end
  31. local function swapKeyValue(tab)
  32.   for a,b in pairs(tab) do
  33.     tab[b] = a
  34.   end
  35.   return tab
  36. end
  37. local function copyTable(tab)
  38.   local toRet = {}
  39.   for a,b in pairs(tab) do
  40.     toRet[a] = b
  41.   end
  42.   return toRet
  43. end
  44. local function checkChannel(num)
  45.   num = tonumber(num)
  46.   if 1 <= num and num <= 65535 then
  47.     return num
  48.   end
  49. end
  50.  
  51. --Initializing Variables
  52. local sendChannel, receiveChannel
  53. local periphSides = {monitor = nil, modem = nil}
  54. local expectedMessage = "Civil's Quarry"
  55. local respondMessage = "Turtle Quarry Receiver"
  56. local stopMessage = "stop"
  57. local sides = swapKeyValue({"top","bottom","right","left","front","back"}) --This allows sides[1] and sides.front
  58. --tArgs and peripheral list init
  59. local tArgs = {...}
  60. local tArgsWithUpper = swapKeyValue(copyTable(tArgs))
  61. for a, b in pairs(tArgs) do --Lower arguments
  62.   tArgs[a] = string.lower(b)
  63. end
  64. tArgs = swapKeyValue(tArgs)
  65. local foundSides = {}
  66. for a, b in pairs(sides) do
  67.   if type(a) == "string" then
  68.     foundSides[a] = peripheral.getType(a)
  69.   end
  70. end
  71. foundSides = swapKeyValue(foundSides)
  72.  
  73. --Size functions
  74. local sizes = {monitor = {51, 19}, turtle = {39,13}, {7, 5}, {18, 12}, {29, 19}, 39, 50} --Monitor dimensions
  75. local sizesEnum = {small = 1, medium = 2, large = 3, monitor = 4, turtle = 5} --For reference
  76. local dim, screenSize
  77. local function setSize()
  78.   if mon == term or not mon.getCursorPos() then --You should be able to swap out screens
  79.     local a = peripheral.wrap(periphSides.monitor or "")
  80.     if a then --If a is a valid monitor then
  81.       mon = a --Monitor variable is a
  82.     else
  83.       mon = term --Monitor variable is just the screen variable
  84.     end
  85.   end
  86.   screenSize = {}
  87.   dim = {mon.getSize()} --Just pretend its large if it doesn't exist
  88.   if dim[1] == sizes.monitor[1] and dim[2] == sizes.monitor[2] then
  89.     screenSize.isComputer = true
  90.   else
  91.     screenSize.isComputer = false
  92.   end
  93.   if dim[1] == sizes.turtle[1] and dim[2] == sizes.turtle[2] then
  94.     screenSize.isTurtle = true
  95.   else
  96.     screenSize.isTurtle = false
  97.   end
  98.   for a=1, 2 do --X and Y
  99.     for i=3, 1, -1 do --Different sizes 1 - 3
  100.       if dim[a] >= sizes[i][a] then --This will get decrementing screen sizes. Can even be adjusted later!
  101.         screenSize[a] = i
  102.         break
  103.       end
  104.     end
  105.   end
  106.   if not (screenSize[1] and screenSize[2]) then error("Screen Size was not set properly") end
  107.   if debug then
  108.     print("Screen Size Reset:")
  109.     print("Size X: ",screenSize[1]," Size Y: ",screenSize[2])
  110.     print("Dim X: ",dim[1]," Dim Y: ",dim[2])
  111.   end
  112. end
  113.  
  114. --Arguments and such
  115. local function getNext(str)
  116.   return tArgs[tArgs[str]+1]
  117. end
  118.  
  119.  
  120. if tArgs["-modem"] then
  121.   if sides[getNext("-modem")] then
  122.     periphSides["modem"] = getNext("-modem")
  123.   end
  124. else --This will check for a modem only if argument isn't specified
  125.   periphSides["modem"] = foundSides["modem"]
  126. end
  127. for _, a in pairs({"-monitor","-screen"}) do
  128.   if tArgs[a] then
  129.     if sides[getNext(a)] then --Checks if the argument following monitor is a valid side
  130.       periphSides.monitor = getNext(a)
  131.     else
  132.       periphSides.monitor = foundSides.monitor --This differs from above so if no argument, will default to screen.
  133.     end
  134.   elseif defaultCheckScreen then
  135.     periphSides.monitor = foundSides.monitor
  136.   end
  137. end
  138.  
  139. if tArgs["-channel"] then
  140.   receiveChannel = checkChannel(getNext("-channel")) --This will be nil if it doesn't exist
  141. end
  142.  
  143. if debug then
  144.   print(textutils.serialize(foundSides))
  145.   print("Screen Side: ",periphSides.monitor)
  146.   print("Modem Side: ",periphSides.modem)
  147.   os.pullEvent("char")
  148. end
  149.  
  150.  
  151. --All UI, handshaking, and monitor finding go here.
  152. term.clear()
  153. term.setCursorPos(1,1)
  154. print("Welcome to Quarry Receiver!")
  155. while peripheral.getType(periphSides["modem"]) ~= "modem" do
  156.   write("Which side is the modem on? " )
  157.   local temp = read()
  158.   if peripheral.getType(temp:lower()) == "modem" then --If the input side is a modem
  159.     periphSides.modem = temp
  160.   else print("That side does not have a modem on it \n") end
  161. end
  162. while not receiveChannel do
  163.   write("What channel? (Check turtle) ")
  164.   local temp = tonumber(read()) or 0
  165.   if checkChannel(temp) then
  166.     receiveChannel = temp
  167.   end
  168. end
  169.  
  170. --Init
  171. local a = peripheral.wrap(periphSides.monitor or "")
  172. if a then --If a is a valid monitor then
  173.   mon = a --Monitor variable is a
  174. else
  175.   mon = term --Monitor variable is just the screen variable
  176. end
  177. setSize()
  178. modem = peripheral.wrap(periphSides.modem)
  179.  
  180. if debug then
  181.   print("Is computer: ",screenSize.isComputer)
  182.   print("Is turtle: ",screenSize.isTurtle)
  183.   os.pullEvent("char")
  184. end
  185.  
  186.  
  187. --Handshake
  188. print("Opening channel ",receiveChannel)
  189. modem.open(receiveChannel)
  190. print("Waiting for turtle message")
  191. repeat
  192.   local event, modemSide, recCheck, sendCheck, message, distance = os.pullEvent("modem_message")
  193.   if debug then print("Message Received") end
  194.   if (message == expectedMessage or (sloppyHandshake and textutils.unserialize(message))) and recCheck == receiveChannel and modemSide == periphSides.modem then
  195.     sendChannel = sendCheck
  196.     sleep(0.5) --Give it a second to catch up?
  197.     modem.transmit(sendChannel, receiveChannel, respondMessage)
  198.     print("Successfully paired, sending back on channel ",sendChannel)
  199.   else
  200.     if debug then print("Invalid message received: ",message) end
  201.   end
  202.  
  203. until sendChannel --This will be assigned when message is received
  204.  
  205.  
  206.  
  207. --[[
  208. Items to add:
  209. +Title with computer name and number
  210. +Dimensions of quarry
  211. +Open space
  212. +Current Fuel
  213. +Percent Done
  214. +Current position x
  215. +Current position z
  216. +Current number of layers done
  217. +Number of blocks mined
  218. +Number of blocks moved
  219. +If going to next layer, if going back to start, if it home position.
  220. +Any errors, like chest is full or something.
  221. Distance to turtle might be cool
  222. ]]
  223. --[[
  224. Needed Fields:
  225. label
  226. percent
  227. relxPos,zPos,layersDone
  228. x, z, layers
  229. openSlots
  230. mined
  231. moved
  232. atHome
  233. chestFull
  234. fuel
  235. volume
  236. ]]
  237. --This is for testing purposes. Rec will be "receivedMessage"
  238. --Nevermind, I actually need a default thing with keys in it.
  239. local rec = {
  240. label = "Quarry Bot",
  241. id = 1,
  242. percent = 0,
  243. relxPos = 0,
  244. zPos = 0,
  245. layersDone = 0,
  246. x = 0,
  247. z = 0,
  248. layers = 0,
  249. openSlots = 0,
  250. mined = 0,
  251. moved = 0,
  252. chestFull = false,
  253. isAtChest = false,
  254. isGoingToNextLayer = false,
  255. foundBedrock = false,
  256. fuel = 0,
  257. volume = 0,
  258. distance = 0,
  259. yPos = 0
  260. --Maybe add in some things like if going to then add a field
  261. }
  262.  
  263. local typeColors = {}
  264. local function addColor(name, text, back) --Background is optional. Will not change if nil
  265.   typeColors[name] = {text = text, background = back}
  266. end
  267.  
  268. addColor("title", colors.green, colors.gray)
  269. addColor("subtitle", colors.white)
  270. addColor("pos", colors.green)
  271. addColor("dim", colors.lightBlue)
  272. addColor("extra", colors.lightGray)
  273. addColor("error", colors.red, colors.white)
  274. addColor("info", colors.blue, colors.lightGray)
  275. addColor("inverse", colors.yellow, colors.lightGray)
  276.  
  277.  
  278. local function reset(color)
  279.   setBackgroundColor(color)
  280.   mon.clear()
  281.   mon.setCursorPos(1,1)
  282. end
  283. local function say(text, color, inc)
  284.   local currColor = currBackgroundColor
  285.   setTextColor(color.text)
  286.   if debug and #text > dim[1] then error("Tried printing: "..text..", but was too big") end
  287.   if color.background then setBackgroundColor(color.background) end
  288.   for i=1, dim[1]-#text do --This is so the whole line's background gets filled.
  289.     text = text.." "
  290.   end
  291.   mon.write(text)
  292.   setBackgroundColor(currColor)
  293.   local pos = ({mon.getCursorPos()})[2] or setSize() or 1
  294.   mon.setCursorPos(1, pos+1)
  295. end
  296.  
  297. local toPrint = {}
  298. local function tryAdd(text, color, ...) --This will try to add text if Y dimension is a certain size
  299.   local doAdd = {...} --booleans for small, medium, and large
  300.   local added = false
  301.   text = text or "-"
  302.   color = color or {text = colors.white}
  303.   for i=1, 3 do
  304.     if doAdd[i] and screenSize[2] == i then --If should add this text for this screen size and the monitor is this size
  305.       table.insert(toPrint, {text = text, color = color})
  306.       added = true
  307.     end
  308.   end
  309.   if not added then return true end --This is so I won't remove elements that haven't been added.
  310.   if #text > dim[1] then return false else return true end
  311. end
  312. local function align(text, number)
  313.   if #text >= number then return text end
  314.   for i=1, number-#text do
  315.     text = " "..text
  316.   end
  317.   return text
  318. end
  319. local function center(text)
  320.   local a = (dim[1]-#text)/2
  321.   for i=1, a do
  322.     text = " "..text.." "
  323.   end
  324.   return text  
  325. end
  326.  
  327. local extraLine --This is used in display and set in commandSender
  328. function display() while true do sleep(0)
  329.   local str = tostring
  330.   local pos = {mon.getCursorPos()}--Record pos so it can be reset
  331.   toPrint = {} --Reset table
  332.   if not isDone then --Normally
  333.     if screenSize[1] == sizesEnum.small then
  334.       if not tryAdd(rec.label or "Quarry!", typeColors.title, false, false, true) then --This will be a title, basically
  335.         toPrint[#toPrint] = nil
  336.         tryAdd("Quarry!", typeColors.title, false, false, true)
  337.       end
  338.      
  339.       tryAdd("-Fuel-", typeColors.subtitle , false, true, true)
  340.       if not tryAdd(str(rec.fuel), nil, false, true, true) then --The fuel number may be bigger than the screen
  341.         toPrint[#toPrint] = nil
  342.         tryAdd("A lot", nil, false, true, true)
  343.       end
  344.      
  345.       tryAdd("--%%%--", typeColors.subtitle, false, true, true)
  346.       tryAdd(align(str(rec.percent).."%", 7), typeColors.pos , false, true, true) --This can be an example. Print (receivedMessage).percent in blue on all different screen sizes
  347.       tryAdd(center(str(rec.percent).."%"), typeColors.pos, true) --I want it to be centered on 1x1
  348.      
  349.       tryAdd("--Pos--", typeColors.subtitle, false, true, true)
  350.       tryAdd("X:"..align(str(rec.relxPos), 5), typeColors.pos, true, true, true)
  351.       tryAdd("Z:"..align(str(rec.zPos), 5), typeColors.pos , true, true, true)
  352.       tryAdd("Y:"..align(str(rec.layersDone), 5), typeColors.pos , true, true, true)
  353.      
  354.       if not tryAdd(str(rec.x).."x"..str(rec.z).."x"..str(rec.layers), typeColors.dim , true) then --If you can't display the y, then don't
  355.         toPrint[#toPrint] = nil --Remove element
  356.         tryAdd(str(rec.x).."x"..str(rec.z), typeColors.dim , true)
  357.       end
  358.       tryAdd("--Dim--", typeColors.subtitle, false, true, true)
  359.       tryAdd("X:"..align(str(rec.x), 5), typeColors.dim, false, true, true)
  360.       tryAdd("Z:"..align(str(rec.z), 5), typeColors.dim, false, true, true)
  361.       tryAdd("Y:"..align(str(rec.layers), 5), typeColors.dim, false, true, true)
  362.      
  363.       tryAdd("-Extra-", typeColors.subtitle, false, false, true)
  364.       tryAdd(align(textutils.formatTime(os.time()):gsub(" ","").."", 7), typeColors.extra, false, false, true) --Adds the current time, formatted, without spaces.
  365.       tryAdd("Open:"..align(str(rec.openSlots),2), typeColors.extra, false, false, true)
  366.       tryAdd("Dug"..align(str(rec.mined), 4), typeColors.extra, false, false, true)
  367.       tryAdd("Mvd"..align(str(rec.moved), 4), typeColors.extra, false, false, true)
  368.       if rec.chestFull then
  369.         tryAdd("ChstFll", typeColors.error, false, false, true)
  370.       end
  371.      
  372.     end
  373.     if screenSize[1] == sizesEnum.medium then
  374.       if not tryAdd(rec.label or "Quarry!", typeColors.title, false, false, true) then --This will be a title, basically
  375.         toPrint[#toPrint] = nil
  376.         tryAdd("Quarry!", typeColors.title, false, false, true)
  377.       end
  378.      
  379.       tryAdd("-------Fuel-------", typeColors.subtitle , false, true, true)
  380.       if not tryAdd(str(rec.fuel), nil, false, true, true) then --The fuel number may be bigger than the screen
  381.         toPrint[#toPrint] = nil
  382.         tryAdd("A lot", nil, false, true, true)
  383.       end
  384.      
  385.       tryAdd(str(rec.percent).."% Complete", typeColors.pos , true, true, true) --This can be an example. Print (receivedMessage).percent in blue on all different screen sizes
  386.      
  387.       tryAdd("-------Pos--------", typeColors.subtitle, false, true, true)
  388.       tryAdd("X Coordinate:"..align(str(rec.relxPos), 5), typeColors.pos, true, true, true)
  389.       tryAdd("Z Coordinate:"..align(str(rec.zPos), 5), typeColors.pos , true, true, true)
  390.       tryAdd("On Layer:"..align(str(rec.layersDone), 9), typeColors.pos , true, true, true)
  391.      
  392.       if not tryAdd("Size: "..str(rec.x).."x"..str(rec.z).."x"..str(rec.layers), typeColors.dim , true) then --This is already here... I may as well give an alternative for those people with 1000^3quarries
  393.         toPrint[#toPrint] = nil --Remove element
  394.         tryAdd(str(rec.x).."x"..str(rec.z).."x"..str(rec.layers), typeColors.dim , true)
  395.       end
  396.       tryAdd("-------Dim--------", typeColors.subtitle, false, true, true)
  397.       tryAdd("Total X:"..align(str(rec.x), 10), typeColors.dim, false, true, true)
  398.       tryAdd("Total Z:"..align(str(rec.z), 10), typeColors.dim, false, true, true)
  399.       tryAdd("Total Layers:"..align(str(rec.layers), 5), typeColors.dim, false, true, true)
  400.       tryAdd("Volume"..align(str(rec.volume),12), typeColors.dim, false, false, true)
  401.      
  402.       tryAdd("------Extras------", typeColors.subtitle, false, false, true)
  403.       tryAdd("Time: "..align(textutils.formatTime(os.time()):gsub(" ","").."", 12), typeColors.extra, false, false, true) --Adds the current time, formatted, without spaces.
  404.       tryAdd("Used Slots:"..align(str(16-rec.openSlots),7), typeColors.extra, false, false, true)
  405.       tryAdd("Blocks Mined:"..align(str(rec.mined), 5), typeColors.extra, false, false, true)
  406.       tryAdd("Spaces Moved:"..align(str(rec.moved), 5), typeColors.extra, false, false, true)
  407.       if rec.chestFull then
  408.         tryAdd("Chest Full, Fix It", typeColors.error, false, true, true)
  409.       end
  410.     end
  411.     if screenSize[1] == sizesEnum.large then
  412.       if not tryAdd(rec.label..align(" Turtle #"..str(rec.id),dim[1]-#rec.label), typeColors.title, true, true, true) then
  413.         toPrint[#toPrint] = nil
  414.         tryAdd("Your turtle's name is long...", typeColors.title, true, true, true)
  415.       end
  416.       tryAdd("Fuel: "..align(str(rec.fuel),dim[1]-6), nil, true, true, true)
  417.      
  418.       tryAdd("Percentage Done: "..align(str(rec.percent).."%",dim[1]-17), typeColors.pos, true, true, true)
  419.      
  420.       local var1 = math.max(#str(rec.x), #str(rec.z), #str(rec.layers))
  421.       local var2 = (dim[1]-5-var1+3)/3
  422.       tryAdd("Pos: "..align(" X:"..align(str(rec.relxPos),var1),var2)..align(" Z:"..align(str(rec.zPos),var1),var2)..align(" Y:"..align(str(rec.layersDone),var1),var2), typeColors.pos, true, true, true)
  423.       tryAdd("Size:"..align(" X:"..align(str(rec.x),var1),var2)..align(" Z:"..align(str(rec.z),var1),var2)..align(" Y:"..align(str(rec.layers),var1),var2), typeColors.dim, true, true, true)
  424.       tryAdd("Volume: "..str(rec.volume), typeColors.dim, false, true, true)
  425.       tryAdd("",nil, false, false, true)
  426.       tryAdd(center("____---- EXTRAS ----____"), typeColors.subtitle, false, false, true)
  427.       tryAdd(center("Time:"..align(textutils.formatTime(os.time()),8)), typeColors.extra, false, true, true)
  428.       tryAdd(center("Current Day: "..str(os.day())), typeColors.extra, false, false, true)
  429.       tryAdd("Used Inventory Slots: "..align(str(16-rec.openSlots),dim[1]-22), typeColors.extra, false, true, true)
  430.       tryAdd("Blocks Mined: "..align(str(rec.mined),dim[1]-14), typeColors.extra, false, true, true)
  431.       tryAdd("Blocks Moved: "..align(str(rec.moved),dim[1]-14), typeColors.extra, false, true, true)
  432.       tryAdd("Distance to Turtle: "..align(str(rec.distance), dim[1]-20), typeColors.extra, false, false, true)
  433.       tryAdd("Actual Y Pos (Not Layer): "..align(str(rec.yPos), dim[1]-26), typeColors.extra, false, false, true)
  434.      
  435.       if rec.chestFull then
  436.         tryAdd("Dropoff is Full, Please Fix", typeColors.error, false, true, true)
  437.       end
  438.       if rec.foundBedrock then
  439.         tryAdd("Found Bedrock! Please Check!!", typeColors.error, false, true, true)
  440.       end
  441.       if rec.isAtChest then
  442.         tryAdd("Turtle is at home chest", typeColors.info, false, true, true)
  443.       end
  444.       if rec.isGoingToNextLayer then
  445.         tryAdd("Turtle is going to next layer", typeColors.info, false, true, true)
  446.       end
  447.     end
  448.   else --If is done
  449.     if screenSize[1] == sizesEnum.small then --Special case for small monitors
  450.       tryAdd("Done", typeColors.title, true, true, true)
  451.       tryAdd("Dug"..align(str(rec.mined),4), typeColors.pos, true, true, true)
  452.       tryAdd("Fuel"..align(str(rec.fuel),3), typeColors.pos, true, true, true)
  453.       tryAdd("-------", typeColors.subtitle, false,true,true)
  454.       tryAdd("Turtle", typeColors.subtitle, false, true, true)
  455.       tryAdd(center("is"), typeColors.subtitle, false, true, true)
  456.       tryAdd(center("Done!"), typeColors.subtitle, false, true, true)
  457.     else
  458.       tryAdd("Done!", typeColors.title, true, true, true)
  459.       tryAdd("Blocks Dug: "..str(rec.mined), typeColors.inverse, true, true, true)
  460.       tryAdd("Cobble Dug: "..str(rec.cobble), typeColors.pos, false, true, true)
  461.       tryAdd("Fuel Dug: "..str(rec.fuelblocks), typeColors.pos, false, true, true)
  462.       tryAdd("Others Dug: "..str(rec.other), typeColors.pos, false, true, true)
  463.       tryAdd("Curr Fuel: "..str(rec.fuel), typeColors.inverse, true, true, true)
  464.     end
  465.   end
  466.  
  467.   reset(colors.black)
  468.   for a, b in ipairs(toPrint) do
  469.     say(b.text, b.color)
  470.   end
  471.   if extraLine then
  472.     mon.setCursorPos(1,dim[2])
  473.     say(extraLine[1],extraLine[2])
  474.   end
  475.   mon.setCursorPos(pos[1], pos[2]) --Reset pos for command sender
  476.  
  477.   if isDone then --Is done :D
  478.     return true
  479.   end
  480.  
  481.   while true do --I want specific events
  482.     event = os.pullEvent() --This should wait for any event to update. Function rednet queues an event once info is set
  483.     if event == "monitor_resize" or event == "peripheral" or event == "peripheral_detach" then
  484.       setSize(); extraLine = nil; break
  485.     elseif event == "updateScreen" or (debug and event == "char") then
  486.       break
  487.     end
  488.   end
  489.  
  490. end end
  491.  
  492. local messageToSend --This will be a command string sent to turtle
  493.  
  494. function rednetHandler() while true do sleep(0)--Super sneaky loop
  495. --Will send rednet message to send if it exists, otherwise sends default message.
  496.   local event, sideCheck, receiveCheck, sendCheck, message, distance = os.pullEvent("modem_message")
  497.   if periphSides.modem == sideCheck and receiveCheck == receiveChannel and sendCheck == sendChannel and message == stopMessage then isDone = true end --Flag for other programs
  498.   if not isDone then --Normally
  499.     if periphSides.modem == sideCheck and receiveCheck == receiveChannel and sendCheck == sendChannel then
  500.       rec = textutils.unserialize(message) or {}
  501.       rec.distance = math.floor(distance)
  502.       if rec then
  503.         os.queueEvent("updateScreen") --Tell display that there is new information
  504.       else
  505.         print("IMPROPER MESSAGE RECEIVED")
  506.         if debug then error("expected Table, got "..message) end
  507.       end
  508.      
  509.       local toSend
  510.       if messageToSend then
  511.         toSend = messageToSend
  512.         messageToSend = nil
  513.       else
  514.         toSend = respondMessage
  515.       end
  516.       modem.transmit(sendChannel, receiveChannel, toSend)
  517.     else
  518.       print("Message was not sent on proper channel/ modem") --Maybe here do something about other channels?
  519.       if debug then
  520.         print("ReceiveCheck: ",receiveCheck," ReceiveChannel: ",receiveChannel)
  521.         print("SendCheck: ",sendCheck," SendChannel: ",sendChannel)
  522.         print("Side: ",periphSides.modem, " SideCheck: ",sideCheck)
  523.         error("improper message received") end
  524.     end
  525.   elseif message ~= stopMessage then --If is done
  526.     if debug then print("Received final final message") end
  527.     modem.close(receiveChannel)
  528.     rec = textutils.unserialize(message)
  529.     if rec then
  530.       os.queueEvent("updateScreen")
  531.     else
  532.       error("Finished with program, but received bad message", 0)
  533.     end
  534.     print("Done with program")
  535.   else --If is done, before final message
  536.     if debug then print("Received final: ", message) end
  537.   end
  538. end end
  539.  
  540.  
  541.  
  542. function commandSender() while true do sleep(0)
  543.   if screenSize.isComputer or screenSize.isTurtle then
  544.     extraLine = {"Command: ", {text = colors.lightBlue}}
  545.     mon.setCursorPos(#extraLine[1]+1, dim[2])
  546.     messageToSend = read()
  547.     os.queueEvent("updateScreen") --Update Screen
  548.   else
  549.     extraLine = nil
  550.   end
  551. end end
  552.  
  553. ------------------------------------------
  554. sleep(0.5)
  555. parallel.waitForAny( commandSender, display, rednetHandler)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top