Advertisement
Stravides

ReactorOnOFF-Receive

Nov 25th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. rednet.open("bottom")
  2. local reactor
  3.  
  4. reactor   = peripheral.wrap("BigReactors-Reactor_1")
  5.  
  6.  
  7. function toggleActive()
  8.   if reactor.getActive()==true then
  9.     reactor.setActive(false)
  10.   else
  11.     reactor.setActive(true)
  12.   end
  13. end  
  14.  
  15. function split(str, delim, maxNb)  
  16.   if string.find(str, delim) == nil then
  17.     return { str }
  18.   end
  19.   if maxNb == nil or maxNb <1 then
  20.     maxNb = 0
  21.   end
  22.   local result = {}
  23.   local pat = "(.-)"..delim.."()"
  24.   local nb = 0
  25.   local lastPos
  26.   for part, pos in string.gmatch(str,pat) do
  27.     nb = nb+1
  28.     result[nb]=part
  29.     lastPos=pos
  30.     if nb==maxNb then break end
  31.   end
  32.   if nb ~= maxNb then
  33.     result[nb+1] = string.sub(str,lastPos)
  34.   end
  35.   return result
  36. end
  37.  
  38. function round(val, decimal)
  39.   if (decimal) then
  40.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  41.   else
  42.     return math.floor(val+0.5)
  43.   end
  44. end
  45.  
  46. function writeAt(x,y,text)
  47.   m.setCursorPos(x,y)
  48.   m.write(text)
  49. end
  50.  
  51. function checkMsg()
  52. local time= os.time()
  53.   local fTime = textutils.formatTime(time,false)
  54.   local event, id, msg = os.pullEvent("rednet_message")
  55.   local Tab = split(msg,"|",2)
  56.   if Tab[1]=="toggleActive" then
  57.     toggleActive()
  58.   end
  59. end
  60.  
  61. print("Program is running <CTRL> <T> to stop")
  62. while true do
  63.   checkMsg()
  64.   sleep(1)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement