Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# you may as well use numbers instead of strings
- local mfsu = {
- peripheral.wrap("mfsu_3");
- peripheral.wrap("mfsu_4");
- peripheral.wrap("mfsu_5");
- peripheral.wrap("mfsu_6");
- peripheral.wrap("mfsu_7");
- peripheral.wrap("mfsu_8");
- peripheral.wrap("mfsu_9");
- peripheral.wrap("mfsu_10");
- peripheral.wrap("mfsu_11");
- }
- local m = peripheral.wrap("monitor_13")
- m.clear()
- local storedEU = {}
- local storedPerc = {}
- local plotter = {}
- local printer = {}
- local energyTotals = 0
- local energyFlow = 0
- local function shorten(num)
- if num then
- return string.format("%.1f", num)
- end
- return "0"
- end
- local function colorPerc(num)
- num = tonumber(num)
- if num then --# you had ~= nil here
- --# order has been switched so elseif can be used
- if num > 90 then
- m.setTextColor(colors.lime)
- elseif num > 60 then
- m.setTextColor(colors.yellow)
- elseif num > 30 then
- m.setTextColor(colors.orange)
- else
- m.setTextColor(colors.red)
- end
- m.write(num.."%")
- space = #tostring(num) - 5 * (-1) --# string.len and # are the same on strings
- for i = 1, space do
- m.write(" ")
- end
- m.setTextColor(colors.white)
- end
- end
- local function storedTotal()
- local energyTotal = 0
- for i = 1,9 do
- energyTotal = energyTotal + mfsu[i].getEUStored() --# removed tostring 'cause the table is now indexes instead of keys
- end
- energyFlow = (energyTotal - energyTotals) / 20
- energyTotals = energyTotal
- energyPercentage = shorten(energyTotal / 360000000 * 100) --# you had tostring on this
- m.setCursorPos(3,3)
- m.write("Total Energy Stored: "..energyTotal.." EU")
- m.setCursorPos(9,4)
- m.write("Total Capacity: ")
- colorPerc(energyPercentage)
- end
- local function storedEach()
- for i = 1,9 do
- storedEU[i] = mfsu[i].getEUStored() --# removed tostring 'cause the table is now indexes instead of keys
- storedPerc[i] = shorten(storedEU[i] / 40000000 * 100) --# you had tostring on this
- end
- m.setCursorPos(1,6)
- for i = 1,3 do
- m.write("MFSU"..i..": ")
- colorPerc(storedPerc[i])
- xPos = i * 14
- m.setCursorPos(xPos,6)
- end
- m.setCursorPos(1,7)
- for i = 4,6 do
- m.write("MFSU"..i..": ")
- colorPerc(storedPerc[i])
- xPos = (i-3) * 14
- m.setCursorPos(xPos,7)
- end
- m.setCursorPos(1,8)
- for i = 7,9 do
- m.write("MFSU"..i..": ")
- colorPerc(storedPerc[i])
- xPos = (i-6) * 14
- m.setCursorPos(xPos,8)
- end
- end
- local function flowChart()
- for i = 1,15 do
- m.setCursorPos(6,(i + 10))
- m.write("|")
- end
- for i = 1,39 do
- m.setCursorPos(i,26)
- m.write("-")
- end
- for i = 1,15 do
- m.setCursorPos(34,(i + 10))
- m.write("|")
- end
- for i = 1,2 do
- if i == 1 then
- yP = 1
- else
- yP = 35
- end
- m.setCursorPos(yP,11)
- m.write("2.1k ")
- m.setCursorPos(yP,13)
- m.write("1.5k ")
- m.setCursorPos(yP,15)
- m.write(" 900 ")
- m.setCursorPos(yP,17)
- m.write(" 300 ")
- m.setCursorPos(yP,19)
- m.write("-300 ")
- m.setCursorPos(yP,21)
- m.write("-900 ")
- m.setCursorPos(yP,23)
- m.write("-1.5k")
- m.setCursorPos(yP,25)
- m.write("-2.1k")
- end
- end
- local function plotPos(num)
- local plotter,plotW,plotR = energyFlow / 300,0,0
- if plotter < 0 then
- plotW = tonumber(string.sub(tostring(plotter),2,2))
- plotR = tonumber(string.sub(tostring(plotter),4,4))
- negative = true
- else
- plotW = tonumber(string.sub(tostring(plotter),1,1))
- plotR = tonumber(string.sub(tostring(plotter),3,3))
- negative = false
- end
- if plotR then
- if plotR >= 5 then
- plotW = plotW + 1
- end
- end
- if not negative then --# you had == false here
- plotW = plotW * (-1)
- end
- return plotW
- end
- local function drawPlots()
- m.setCursorPos(12,26)
- m.write("--("..energyFlow.." EU/t)--------")
- yPos = plotPos(energyFlow) + 18
- printer[34] = yPos
- for i = 7,33 do
- j = i + 1
- h = i
- printer[i] = printer[j]
- for i = 11,25 do
- m.setCursorPos(h,i)
- if i == printer[h] then
- if i < 18 then
- m.setBackgroundColor(colors.cyan)
- else
- m.setBackgroundColor(colors.blue)
- end
- else
- m.setBackgroundColor(colors.black)
- end
- m.write(" ")
- m.setBackgroundColor(colors.black)
- end
- end
- end
- local function label()
- m.setCursorPos(13,1)
- m.write("Energy Monitor")
- m.setCursorPos(1,10)
- m.write("---------- Energy Flow (EU/t)----------")
- end
- label()
- flowChart()
- while true do
- storedTotal()
- storedEach()
- drawPlots()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment