flaghacker, on 21 July 2015 - 06:50 AM, said:
names = {"monitor_1", "..."}
monitors = {}
for i, name in ipairs (names) do
monitors[i] = peripheral.wrap (name)
end
...
Yes, if you are going to repeatedly access/change these monitors, I second flaghacker's approach of making a table of wrapped monitors (opposed to just a table of their string names) so you can easily pull them back up without needed to rerun the peripheral.wrap loop.
It also looks like you want to have updating time on the signs, so maybe something like this will strike the right balance for simplicity:
print('Store Sign Engaged')
text = "Welcome to Renegade Inc"
names = {"monitor_6", "monitor_7",
"monitor_8", "monitor_9",
"monitor_10", "monitor_11",
"monitor_12", "monitor_13"}
monitors = {}
for i, name in ipairs (names) do
monitors[i] = peripheral.wrap (name)
monitors[i].setTextScale(2)
-- Anything else you want to set up the first time
end
while true do
for _, mon in ipairs (monitors) do
mon.clear()
mon.setCursorPos(1,1)
mon.write(text)
mon.setCursorPos(1,2)
mon.write(textutils.formateTime(os.time(),false))
end
sleep(1)
end
Also, if you don't want to hardcode your monitor names (in case you add, remove, or move them around) you can use the
peripheral API to automatically find them like so:
local names = peripheral.getNames()
local monitors = {}
for _, v in ipairs(names) do
if(string.find(v, "monitor")) then
table.insert(monitors, peripheral.wrap(v))
end
end
*This only works for networked monitors (since they have "monitor" in their name) and won't see monitors directly touching the computer.
flaghacker, on 21 July 2015 - 06:50 AM, said:
Edit:
, read the post above me for an excellent explenation on for loops
Appreciate that.