local rValue = math.random(1000, 9999) --has no actual effect on the operation of the program
while true do --enter our loop
local pList = peripheral.getNames()
local i, name
--get the full device names
function getMonitorName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "monitor" then
return peripheral.wrap(name)
end
end
end
function getMatrixName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "Induction Matrix" then
return peripheral.wrap(name)
end
end
end
function getbCubeName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "Basic Energy Cube" then
return peripheral.wrap(name)
end
end
end
function getaCubeName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "Advanced Energy Cube" then
return peripheral.wrap(name)
end
end
end
function geteCubeName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "Elite Energy Cube" then
return peripheral.wrap(name)
end
end
end
function getuCubeName()
for i, name in pairs(pList) do
if peripheral.getType(name) == "Ultimate Energy Cube" then
return peripheral.wrap(name)
end
end
end
--set the short name aliases
local mon = getMonitorName()
local matrix = getMatrixName()
local bCube = getbCubeName()
local aCube = getaCubeName()
local eCube = geteCubeName()
local uCube = getuCubeName()
local sType = 0 --storage type counter
--quick formatting aliases
function mCursor(x,y) --monitor cursor alias
mon.setCursorPos(x,y)
end
function tCursor(x,y) --terminal cursor alias
term.setCursorPos(x,y)
end
function nText() --nominal text (need to rework later)
mon.setTextColor(colors.lime)
end
function hText() --header text
mon.setTextColor(colors.white)
end
function iText() --info text
mon.setTextColor(colors.yellow)
end
function cText() --caution text
mon.setTextColor(colors.orange)
end
function wText() --warning text
mon.setTextColor(colors.red)
end
function tReset() --reset terminal to initial state
term.clear()
tCursor(1,1)
end
function mReset() --reset monitor to initial state
mon.clear()
mCursor(1,1)
end
if mon == nil then --detect if a monitor exists, error if it doesn't
tReset()
print("Error -1\n")
print("This system was designed to output to a",
"monitor, but one couldn't be found. Please",
"attach a monitor to any side of the terminal",
"or with a wired modem.")
else
tReset()
print("Process ID:", rValue)
print("Status: Running...")
end
if matrix ~= nil then --detect if an Induction Matrix exists, set method aliases if it does
mEnergy = matrix.getEnergy()
mMaxEnergy = matrix.getMaxEnergy()
mInput = matrix.getInput()
mOutput = matrix.getOutput()
mXFerCap = matrix.getTransferCap()
sType = sType+1
end
if bCube ~= nil then --detect if a Basic Energy Cube exists, set method aliases if it does
bEnergy = bCube.getEnergy()
bMaxEnergy = bCube.getMaxEnergy()
bEnergyNeeded = bCube.getEnergyNeeded()
bOutput = bCube.getOutput()
sType = sType+1
end
if aCube ~= nil then --detect if an Advanced Energy Cube exists, set method aliases if it does
aEnergy = aCube.getEnergy()
aMaxEnergy = aCube.getMaxEnergy()
aEnergyNeeded = aCube.getEnergyNeeded()
aOutput = aCube.getOutput()
sType = sType+1
end
if eCube ~= nil then --detect if an Elite Energy Cube exists, set method aliases if it does
eEnergy = eCube.getEnergy()
eMaxEnergy = eCube.getMaxEnergy()
eEnergyNeeded = eCube.getEnergyNeeded()
eOutput = eCube.getOutput()
sType = sType+1
end
if uCube ~= nil then --detect if an Ultimate Energy Cube exists, set method aliases if it does
uEnergy = uCube.getEnergy()
uMaxEnergy = uCube.getMaxEnergy()
uEnergyNeeded = uCube.getEnergyNeeded()
uOutput = uCube.getOutput()
sType = sType+1
end
function putNumber (number) --round numbers and make them into human readable format
local round = 0
local texts = ""
if number >= 1000000000000000000 then
round = (number / 1000000000000000000)
texts = string.sub(round, 0, 5) .. " EJ"
elseif number >= 1000000000000000 then
round = (number / 1000000000000000)
texts = string.sub(round, 0, 5) .. " PJ"
elseif number >= 1000000000000 then
round = (number / 1000000000000)
texts = string.sub(round, 0, 5) .. " TJ"
elseif number >= 1000000000 then
round = (number / 1000000000)
texts = string.sub(round, 0, 5) .. " GJ"
elseif number >= 1000000 then
round = (number / 1000000)
texts = string.sub(round, 0, 5) .. " MJ"
elseif number >= 1000 then
round = (number / 1000)
texts = string.sub(round, 0, 5) .. " kJ"
else
round = (number)
texts = string.sub(number, 0, 5) .. " J"
end
return texts
end
mReset()
mon.write(putNumber(bEnergy))
mCursor(1,2)
mon.write(putNumber(aEnergy))
mCursor(1,3)
mon.write(putNumber(eEnergy))
mCursor(1,4)
mon.write(putNumber(uEnergy))
mCursor(1,5)
mon.write(putNumber(mEnergy)) mon.write(putNumber(mMaxEnergy))
--[[
if sType == 0 then
mReset()
mon.write("ERROR: No power storage detected.")
mCursor(1,3)
mon.write("System TERMINATED.")
mCursor(1,5)
mon.write("Please connect power storage")
tReset()
break
elseif sType > 1 then
mReset()
mon.write("ERROR: Multi-Type Storage Detected")
mCursor(1,3)
mon.write("System TERMINATED")
tReset()
break
end
--]]
sleep(1) --wait for 1sec
end --exit our loop
Comments