There is actually a LOT better way to do this with loops and the already available modem.getNamesRemote makes it so you can allow for an unlimited amount of reator/turbines.
Lets start with finding your wired modem that you're connecting to the turbines and reactors with, as well as finding the monitor.
Spoiler
local function findPeriph(arg1) --#Declare the function findPeriph with the parameter arg1
for a,v in pairs({"top","bottom","left","right","back","front"}) do --#Look through the specified table of sides. a is the numerical index/string index of the item
--#so in this case top is 1 bottom is 2 and so on.
--#v is the word itself, top bottom left right and so on. And it will go through them one at a time, very useful :P/>/>
if peripheral.getType(v) == arg1 then --#If the side is what we're looking for
return v --#Return the side
end
end
error("Cannot find " .. arg1 .. " connected to computer",0) --# If the device we're looking for cannot be found, tell them.
end
local modem = peripheral.wrap(findPeriph("modem")) --#Look for and wrap the modem
local mon = peripheral.wrap(findPeriph("monitor")) --#Look for and wrap the monitor
So this code is a simple one, and i use it quite a bit as i need to sometimes find certain peripherals connected to a computer, and rather than force myself to hard code one side, i make it check them all.
Next you want to setup the monitor and start printing out the states (I leave the turbine names until last so that i can know how many there are)
Spoiler
mon.clear()
mon.setTextScale(1)
mon.setBackgroundColour(colors.black)
local function printConnected(arg1,arg2,count)
local s = 3
--#in this case arg1 is what we're looking for, and arg2 is the x position we're printing to
for a,v in pairs(modem.getNamesRemote()) do --#It grabs the names of all remotely attached peripherals.
--#Just like you did at the top of your code manually.
if peripheral.getType(v) == arg1 then --#Peripheral.getType gets what it is from the name.
--#So a monitor is monitor modem is modem and so on.
if count then --#If we should keep count. (I don't use this for getting the reactors)
maxturbines += 1 --#Add one to the max
end
mon.setCursorPos(arg2,s)--#Set it in the correct spot
local active = peripheral.call(v,"getActive") --#This is local z = peripheral.wrap("peripheral") and then z.getActive()
if active then --#If it's active.
mon.setBackgroundColor(colors.gray)
mon.write(" ONLINE ")
elseif not active then --#If it's not active
mon.setBackgroundColor(colors.red)
mon.write(" OFFLINE ")
end
mon.setBackgroundColor(colors.black)
s += 1 --Add one to the line so we go to the next
end
end
end
printConnected("BigReactors-Turbine",14,true) --#Call printConnected and tell it we're looking for BigReactors-Turbine and put it at mon.setCursorPos(14,y) and we're going to count.
printConnected("BigReactors-Reactor",22) --#Call printConnected and tell it we're looking for BigReactors-Reactor and put it at mon.setCursorPos(22,y)
And finally we need to print out the numbers of our reactors.
Spoiler
mon.setCursorPos(1,1)
mon.write(" Global Turbine Overview")
mon.setCursorPos(1,2)
mon.write(" -----------------------")
for num = 1, maxturbines do --#Starting at one and ending at the amount connected, count up one
mon.setCursorPos(1,num+2) --#Set the cursor to the correct spot
mon.write("Turbine #"..string.format("%02d",num)) --# %02d says add a 0 if a number is less than 2 digits
--#Print it out, I'm using string.format to make sure it has a digit in the tens place
end
And now the finished product :D/>
Spoiler
local function findPeriph(arg1)
for a,v in pairs({"top","bottom","left","right","back","front"}) do
if peripheral.getType(v) == arg1 then
return v
end
end
error("Cannot find " .. arg1 .. " connected to computer")
end
local modem = peripheral.wrap(findPeriph("modem"))
local mon = peripheral.wrap(findPeriph("monitor"))
local maxturbines = 0
mon.clear()
mon.setTextScale(1)
mon.setBackgroundColour(colors.black)
local function printConnectted(arg1,arg2,count)
local s = 3
--#in this case arg1 is what we're looking for, and arg2 is the x position we're printing to
for a,v in pairs(modem.getNamesRemote()) do --#It grabs the names of all remotely attached peripherals.
--#Just like you did at the top of your code manually.
if peripheral.getType(v) == arg1 then --#Peripheral.getType gets what it is from the name.
--#So a monitor is monitor modem is modem and so on.
if count then --#If we should keep count. (I don't use this for getting the reactors)
maxturbines += 1 --#Add one to the max
end
mon.setCursorPos(arg2,s)--#Set it in the correct spot
local active = peripheral.call(v,"getActive")
if active then --#If it's active.
mon.setBackgroundColor(colors.gray)
mon.write(" ONLINE ")
elseif not active then --#If it's not active
mon.setBackgroundColor(colors.red)
mon.write(" OFFLINE ")
end
mon.setBackgroundColor(colors.black)
s += 1 --Add one to the line so we go to the next
end
end
end
printConnected("BigReactors-Turbine",14,true)
printConnected("BigReactors-Reactor",22)
mon.setCursorPos(1,1)
mon.write(" Global Turbine Overview")
mon.setCursorPos(1,2)
mon.write(" -----------------------")
for num = 1, maxturbines do --#Starting at one and ending at the amount connected, count up one
mon.setCursorPos(1,num+2) --#Set the cursor to the correct spot
mon.write("Turbine #"..string.format("%02d",num)) --# %02d says add a 0 if a number is less than 2 digits
--#Print it out, I'm using string.format to make sure it has a digit in the tens place
end
This should work for wherever you try to put it, however it doesn't print out idle for you.