71 posts
Location
Everywhere and nowhere.
Posted 05 May 2018 - 02:52 PM
I am making a loading bar for my installer, and it won't work.
Here is the code:
local function drawBar(startX,endX,fileAmount,currentFile)
paintutils.drawLine(startX,y/2+2,endX,y/2+2,colors.gray)
term.setBackgroundColor(colors.cyan)
string.rep(" ",fileAmount/currentFile)
end
Thanks!
1426 posts
Location
Does anyone put something serious here?
Posted 05 May 2018 - 04:06 PM
You never actually do anything with the repeated string: you create it and then throw it away. You probably wanted something like:
term.write(string.rep(" ",fileAmount/currentFile))
71 posts
Location
Everywhere and nowhere.
Posted 05 May 2018 - 04:21 PM
Oh, my bad. Thanks!
Instead of going forward, it goes backward, and the closer it gets to the end, the slower the bar moves.
749 posts
Location
BOO!!
Posted 05 May 2018 - 04:43 PM
local function drawBar(startX,endX,fileAmount,currentFile)
paintutils.drawLine(startX, y/2+2, endX, y/2+2, colors.gray)
term.setBackgroundColor(colors.cyan)
term.setCursorPos(startX, y)
term.write(string.rep(" ",currentFile/fileAmount*(endX-startX)))
end
Edited on 05 May 2018 - 02:46 PM
477 posts
Location
Germany
Posted 06 May 2018 - 06:16 AM
local function drawBar(startX,endX,fileAmount,currentFile)
paintutils.drawLine(startX, y/2+2, endX, y/2+2, colors.gray)
term.setBackgroundColor(colors.cyan)
term.setCursorPos(startX, y)
term.write(string.rep(" ",currentFile/fileAmount*(endX-startX)))
end
You can use paintutils for the second line too: (This also fixes a Problem with your code where the bar would be drawn at the bottom instead of y/2+2)
local function drawBar(startX,endX,fileAmount,currentFile)
paintutils.drawLine(startX, y/2+2, endX, y/2+2, colors.gray)
paintutils.drawLine(startX, y/2+2, startX+currentFile/fileAmount*(endX-startX), y/2+2, colors.cyan)
end
Edited on 06 May 2018 - 04:46 AM