http://pastebin.com/Nu5kBxHH
That is my progam. Thanks for looking at my post.
Draw a line (paintutils.drawLine) from the start of the progress bar to the start of the progress bar(-1?) + the whole number. You may have to subtract one form the start to make it work better, however that may involve a bit of testing. If you would like you may also make a line the size of the whole progress bar.
How would I got about using monitor.write(" ") multiple times without having a bunch of if statements?Draw a line (paintutils.drawLine) from the start of the progress bar to the start of the progress bar(-1?) + the whole number. You may have to subtract one form the start to make it work better, however that may involve a bit of testing. If you would like you may also make a line the size of the whole progress bar.
You can easily draw a horizontal line without paintutils, just set the background colour to the colour of the line and term.write(" ") as many times as the line's length is in pixels.
term.setBackgroundColour(colours.white)
term.write((" "):rep(math.floor(progress / maxProgress) * barWidth))
I'm having trouble implementing any of this. I don't know what's wrong, but Lemmmy's code doesn't display anything.
mon = peripheral.wrap(monSide) --Wraps the peripheral
oldTerm = term.redirect(mon) --Redirects the term while storing the old term in a variable named oldTerm
coloredPortion = math.floor((currentPower/maxPower) * width) --Calculates the width of the colored portion
paintutils.drawLine(startX, y, startX + width, y, barColor) --Draws the bar
paintutils.drawLine(startX,y,startX + coloredPortion, coloredPart) --Draws the colored portion over the bar
term.redirect(oldTerm) --Sets the term back to normal
function drawLine(x,y,length,color) --Defines the function
oldBgColor = term.getBackgroundColor() --Gets the current background color
for i = x, (length + x) do --Starts a for loop starting at x and ending when x gets to x + length
term.setCursorPos(i,y) --Set the cursor position to i,y
term.setBackgroundColor(color) --Set the background color to the color
term.write(" ") --Write that color to the screen
end
term.setBackgroundColor(oldBgColor) --Reset the background color
end
drawLine(startX, y, width, barColor) --Draws the bar
drawLine(startX, y, coloredPortion, coloredPart) --Draws the colored part over the bar
Thanks! What you said really helped me out. I'll take a closer look at what you posted to try to understand better. I tweaked the code a bit to fit what I'm doing.I like to use a for loop for stuff like this. However you can use paintutils if you redirect to the monitor.
Like thismon = peripheral.wrap(monSide) --Wraps the peripheral oldTerm = term.redirect(mon) --Redirects the term while storing the old term in a variable named oldTerm coloredPortion = math.floor((currentPower/maxPower) * width) --Calculates the width of the colored portion paintutils.drawLine(startX, y, startX + width, y, barColor) --Draws the bar paintutils.drawLine(startX,y,startX + coloredPortion, coloredPart) --Draws the colored portion over the bar term.redirect(oldTerm) --Sets the term back to normal
However if you have an irrational aversion to paintutils like myself or you don't want to redirect the term, you can create your own draw line method like thisfunction drawLine(x,y,length,color) --Defines the function oldBgColor = term.getBackgroundColor() --Gets the current background color for i = x, (length + x) do --Starts a for loop starting at x and ending when x gets to x + length term.setCursorPos(i,y) --Set the cursor position to i,y term.setBackgroundColor(color) --Set the background color to the color term.write(" ") --Write that color to the screen end term.setBackgroundColor(oldBgColor) --Reset the background color end
Of course should you decide to use this function you would have to tweak the first block of code. Just change the paintutils.drawLine() functions to this.drawLine(startX, y, width, barColor) --Draws the bar drawLine(startX, y, coloredPortion, coloredPart) --Draws the colored part over the bar
There you go, hope I could help.
I'm inclined to think you've rigged things such that math.floor(progress / maxProgress) * barWidth resolves to 0 (or perhaps <1). Show us the code you used if you're still stuck.
I'm having trouble implementing any of this. I don't know what's wrong, but Lemmmy's code doesn't display anything.
term.setBackgroundColour(colours.white)
term.write((" "):rep(math.floor(progress / maxProgress * barWidth)))