Posted 21 September 2013 - 11:02 AM
Hi, I'm trying to make a program that prints out to a monitor the percentage of power that I have in my MFSU that is also right next to the computer. I've managed to get the code to where it will print the first part of what I want it to print in white, the change the colour based on what the percentage is and then print the number with a percent sign. The only issue I'm running into is the refresh part. I have this doing it in a loop, but after it prints and works for the first time it just stops working. If someone could help me fix this and make it work that would be great!
Code:
Thanks to anyone who can help me out with this!
Code:
Spoiler
MFSU = peripheral.wrap("right")
m = peripheral.wrap("left")
power = MFSU.getStored()
cap = MFSU.getCapacity()
function round(num)
local mult = 10 ^ 0
return math.floor(num*mult)/mult
end
percent = round((power/cap)*100)
function chooseColor()
if percent < 25 then
col = 16384
return col
elseif percent < 50 then
col = 2
return col
elseif percent < 101 then
col = 8192
return col
end
return col
end
function writeText(col,text)
term.setTextColor(col)
write(text)
end
while true do
term.redirect(m)
term.clear()
m.setTextScale(2)
term.setCursorPos(1,1)
term.setTextColor(1)
write ("Current Power Stored: ")
writeText(chooseColor(),percent)
print "%"
term.restore()
sleep(0.1)
end