Advertisement
Guest User

enginecontrols

a guest
Aug 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. shell.run("clear")
  2. rednet.open("back")
  3. prot = "engines"
  4. run = true
  5. print("ENGINE CONTROLS")
  6.  
  7. cTable = {
  8.            ["green"] = colors.green,
  9.            ["red"] = colors.red
  10.          }
  11.  
  12. function listen()
  13.   while true do
  14.     sId, msg = rednet.receive(prot)
  15.     tColor = msg:sub(msg:find("|")+1)
  16.     term.setTextColor(cTable[tColor])
  17.     print(msg:sub(1,msg:find("|")-1))
  18.     term.setTextColor(colors.white)
  19.     write("> ")
  20.   end
  21. end
  22.  
  23. function processCommands()
  24.   while true do
  25.     write("> ")  
  26.     local isvalid = true
  27.     local cmd = read()
  28.     local rId
  29.    
  30.     if cmd:find("quarry") ~= nil then
  31.       rId = 10
  32.     elseif cmd:find("chipsets") ~= nil then
  33.       rId = 9
  34.     elseif cmd:find("all") ~= nil then
  35.       rId = -1
  36.     elseif cmd:find("clear") ~= nil then
  37.       term.clear()
  38.       term.setCursorPos(1,1)
  39.       print("ENGINE CONTROLS")
  40.     elseif cmd:find("exit") ~= nil then
  41.       term.clear()
  42.       term.setCursorPos(1,1)
  43.       rednet.close("back")
  44.       run = false
  45.       break
  46.     else
  47.       isvalid = false
  48.       print("Enter a valid command")
  49.     end
  50.  
  51.     if isvalid and rId ~= nil then
  52.       if rId > 0 then
  53.         rednet.send(rId, cmd, prot)
  54.       elseif rId == -1 then
  55.         rednet.broadcast(cmd, prot)
  56.       end
  57.     end
  58.   end
  59. end
  60.  
  61. while run do
  62.   parallel.waitForAny(listen, processCommands)
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement