theoriginalbit, you code is awesome but it doesn't work if I try to put the first part into a custom api. Am I missing something?
I also had a custom error message which see it cause some issues too…
API "zDrive"
--Set up two peripherals
function findTperipherals(p)
s = {}
for _,v in pairs(rs.getSides()) do
if #s == 2 then break end
if peripheral.getType(v) == p then
table.insert(s, v)
end
end
return unpack( s )
end
function wrapTperipherals(j, l, k, m)
if k ~= nil then
MO = 2
l = peripheral.wrap(j)
advMon(l, j)
m = peripheral.wrap(k)
advMon(m, k)
elseif j ~= nil then
MO = 1
l = peripheral.wrap(j)
advMon(l, j)
notes("IMPORTANT", "With a second advanced monitor","you will see more information.")
sleep(3)
else
niceError("No advanced monitors attached to the computer","")
return
end
end
--Header function
function header(te)
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setTextColor(colors.white)
end
--Error Messages
function niceError(Ea, Eb)
header("Error!")
term.setCursorPos(1, 3)
cprint(Ea)
cprint(Eb)
local x, y = term.getCursorPos()
if Eb == "" then
y2 = y
elseif Eb ~= "" then
y2 = y + 1
end
term.setCursorPos(1, y2)
term.setTextColor(colors.cyan)
cprint("---------========= Error! =========---------")
term.setTextColor(colors.white)
error()
end
--Center text print
function cprint (t)
local x2, y2 = term.getCursorPos()
local x, y = term.getSize()
term.setCursorPos(math.ceil((x/2) - (t:len()/2)), y2)
print(t)
end
--Notes
function notes(te, ta, tb)
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setCursorPos(1, 3)
term.setTextColor(colors.white)
cprint(ta)
cprint(tb)
term.setCursorPos(1, 6)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setCursorPos(1, 8)
term.setTextColor(colors.white)
end
My program:
--Set up two peripherals
MO = 0
Moni1, Moni2 = zDrive.findTperipherals("monitors")
--Moni1 holds side info and mon1 is variable to write with
zDrive.wrapTperipherals(Moni1, mon1, Moni2, mon2)
mon1.write("This is Monitor 1!")
mon2.write("This is Monitor 2!")
print("There is "..MO.."/2 monitors connected.")