Advertisement
Guest User

init

a guest
Nov 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. local args = {...}
  2. local verbose = args[1] == "true" and true or false
  3. local p = peripheral
  4.  
  5. function vprint(...)
  6.   if verbose == true then
  7.     print("[INIT] ", ...)
  8.   end
  9. end
  10.  
  11. function wrapWiredModem()
  12.   local modems = {}
  13.   local sides = {"front","back","right","left","top","bottom"}
  14.   for n,side in ipairs(sides) do
  15.     if (p.isPresent(side))
  16.         and (p.getType(side) == "modem"
  17.         and (not p.call(side, "isWireless")))
  18.       then modems[#modems+1] = side end
  19.   end
  20.   if #modems ~= 1 then
  21.     if #modems > 1 then
  22.       printError("[INIT] More than one wired modem found!\n[INIT] Please only connect one wired modem and reboot.")
  23.       do return end
  24.     end
  25.     if #modems < 1 then
  26.       printError("[INIT] No wired modems found!\n[INIT] Please connect a wired modem and reboot.")
  27.       do return end
  28.     end
  29.   end
  30.   vprint("found modem on the ", modems[1], " side")
  31.   return p.wrap(modems[1])
  32. end
  33.  
  34. _modem = wrapWiredModem()
  35. _reactors = {}
  36. _turbines = {}
  37.  
  38. vprint("Registering connected devices")
  39.  
  40. for i,v in pairs(_modem.getNamesRemote()) do
  41.   local t = _modem.getTypeRemote(v)
  42.   if string.find(t, "BigReactors") ~= nil then
  43.     if t == "BigReactors-Reactor" then
  44.       _reactors[#_reactors+1] = p.wrap(v)
  45.     end
  46.     if t == "BigReactors-Turbine" then
  47.       _turbines[#_turbines+1] = p.wrap(v)
  48.     end
  49.   end
  50. end
  51.  
  52. vprint("All ", #_reactors + #_turbines, " peripherals registered.")
  53.  
  54. _init_has_run = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement