Advertisement
civilwargeeky

Quarry Receiver 3.5.2

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