I guess, though really the point is for you to understand these things well enough to write them yourself. Since you presumably want the loop to run indefinitely, we'll use a while true do loop. The first thing we do inside the loop is call
os.pullEvent("redstone") , so that the program waits for a change in the redstone inputs. Then we check the redstone inputs using the redstone API functions. This part is somewhat dependent on your setup, for now I'll just pretend you have a bundled cable split from the connection between the switches and whatnot, and red is the Coal generators. We use the result of
rs.getBundledInput("left") to decide whether to write "On" or "Off".
while true do
mon.setCursorPos(1,1)
os.pullEvent("redstone")
local rsnpt = rs.getBundledInput("left")
print("Coal Generators:"..(colors.test(rsnpt,colors.red) and " On" or " Off"))
print("Geothermal Generators: "..(colors.test(rsnpt,colors.green) and " On" or " Off"))
print("Wind Mill: "..(colors.test(rsnpt,colors.blue) and " On" or " Off"))
endYou can add additional print statements of the same form...okay, I'll just do a couple more examples above. See, all that changes is the name of the device and the wire color.
I guess I should explain. What I'm doing is concatenating either " On" or " Off" onto the end of the string to be printed. I decide which by setting up a logic operation that emulates something called a ternary operator (if you know what that is you don't need to read the explanation, though there are some differences between Lua logic and ternary). (X and Y) evaluates to X if it is false or nil, and Y otherwise. So something like colors.test(rsnpt,colors.red) and " On" will result in false if the red wire wasn't powered, and " On" otherwise. Similarly, (X or Y) evaluates to X if it is NOT false or nil, and Y otherwise. So if colors.test(rsnpt,colors.red) was true, and thus the and evaluated to " On", then the or will still evaluate to " On". If the test were false, and thus the previous and evaluated to false, the or will evaluate to " Off".
It should be noted that the and operation has precedence over the or operation, so where parenthesis are not used to specify a different order of evaluation, ands will be evaluated first.