Posted 15 May 2015 - 09:20 PM
Hey everyone! i am trying to make a progress bar on a monitor. the methods on this forum only work on computers, not on monitors.
here is my code:
the problem is i keep a red monitor, no green.
note that it instantly fills the monitor with red
here is my code:
p = peripheral.wrap("right") -- wrap Energy cell
m = peripheral.wrap("top") -- wrap monitor
m.setTextColor(colors.green) -- set colors
m.setBackgroundColor(colors.red)
term.clear()
function getInfo()
me = p.getMaxEnergyStored() -- get energy levels
e = p.getEnergyStored() -- ..
end
function calculate()
-- perc = percentage
perc = e / me -- e.g. 1000/4000 returns 0.25
perc = perc * 100 -- needed for calculation
end
function getMonitor()
x,y = m.getSize() -- get size
Xvalue = x / 100 -- get multiplier
end
function display()
monperc = perc * Xvalue -- amount of pixels to fill
fillspace = math.ceil(monperc) -- get number, e.g. not 1,5
m.clear() -- clear monitor
for i = 1,fillspace do
for l = 1,y do
m.setCursorPos(i,l)
m.write(" ") -- does NOT change anything
l = l + 1
end
i = i + 1
end
end
while true do --loop
getInfo()
sleep(0.1) -- short interval due to lagg issues
calculate()
sleep(0.1)
getMonitor()
sleep(0.1)
display()
sleep(0.3)
end
the problem is i keep a red monitor, no green.
note that it instantly fills the monitor with red
Edited on 15 May 2015 - 07:22 PM