This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
dcleondc's profile picture

% Bar

Started by dcleondc, 27 February 2012 - 11:50 PM
dcleondc #1
Posted 28 February 2012 - 12:50 AM
i want to know how to make it show how many times it has gone through the code for my obsidian generator, when it starts up it will ask you how many pieces of obsidian you want and my friend enter 50. after about 20 obsidian we forgot how many were left it had to make. so i want to know how to make it so every time one piece of obsidian is made it will show how many it has made for example. if my friend said he wanted 20 after i mad one it would say 1/20, and after it made 2 it would say 2/20, and so on.
Advert #2
Posted 28 February 2012 - 01:07 AM
If you don't mind, could you post your code, and format your post better? Right now, it's a minature wall of text that's hard to read.

You could simply do something like this:

local count, numberToMake = 0, 20 -- We start at 0, and we want 20.
<your code here>
<insert this when you complete an obsidian>
count = count + 1
print(count, "/", numberToMake, " obsidian done.")
<more of your code>
dcleondc #3
Posted 28 February 2012 - 01:23 AM
um is there a way to get the code if i made it so the program starts when the computer gets turned on
Luanub #4
Posted 28 February 2012 - 01:47 AM
create a file simply called startup in the root directory of the computer/turtle, in it put..

shell.run( program )
dcleondc #5
Posted 28 February 2012 - 02:38 AM
here is my code for the generator

print ("How many obsidion do you want?")
input = read()
num = tonumber(input)
shell.run("clear")
print ("Please wait")
if num then
for i=1, num do
rs.setBundledOutput("back", colors.red)
sleep(0.5)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.blue)
sleep(3.0)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.white)
shell.run("clear")
print ("Done")
sleep(1.0)
shell.run("clear")
end
end
shell.run("shutdown")
dcleondc #6
Posted 28 February 2012 - 02:39 AM
If you don't mind, could you post your code, and format your post better? Right now, it's a minature wall of text that's hard to read.

You could simply do something like this:

local count, numberToMake = 0, 20 -- We start at 0, and we want 20.
<your code here>
<insert this when you complete an obsidian>
count = count + 1
print(count, "/", numberToMake, " obsidian done.")
<more of your code>
this is my code

print ("How many obsidion do you want?")
input = read()
num = tonumber(input)
shell.run("clear")
print ("Please wait")
if num then
for i=1, num do
rs.setBundledOutput("back", colors.red)
sleep(0.5)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.blue)
sleep(3.0)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.white)
shell.run("clear")
print ("Done")
sleep(1.0)
shell.run("clear")
end
end
shell.run("shutdown")
Advert #7
Posted 28 February 2012 - 03:32 AM
If you don't mind, could you post your code, and format your post better? Right now, it's a minature wall of text that's hard to read.

You could simply do something like this:

local count, numberToMake = 0, 20 -- We start at 0, and we want 20.
<your code here>
<insert this when you complete an obsidian>
count = count + 1
print(count, "/", numberToMake, " obsidian done.")
<more of your code>
this is my code

print ("How many obsidion do you want?")
input = read()
num = tonumber(input)
shell.run("clear")
print ("Please wait")
if num then
for i=1, num do
rs.setBundledOutput("back", colors.red)
sleep(0.5)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.blue)
sleep(3.0)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.white)
shell.run("clear")
print ("Done")
sleep(1.0)
shell.run("clear")
end
end
shell.run("shutdown")


You're using shell.run in a lot of places where you can use functions:

shell.run("clear")
-- is the same as:
term.clear()
---
shell.run("shutdown")
-- is the same as:
os.shutdown()

I'd add a print after the start of the for loop, showing which # it's currently on; but you could of course calculate the time left, if you wanted to.
thet3rminat0r #8
Posted 28 February 2012 - 05:20 AM
Here is a very hackish way to do it but it works and doesnt look bad at all.



while true do
print ("How much obsidian do you want?")
input = read()
num = tonumber(input)
shell.run("clear")
print ("Please Wait While I am Processing Your Order")
loadbar=""
if num then
for i=1, num do
percentage= i/num*100
rs.setBundledOutput("back", colors.red)
sleep(0.5)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.blue)
sleep(3.0)
rs.setBundledOutput("back", colors.yellow)
sleep(0.5)
rs.setBundledOutput("back", colors.white)
if percentage<10 
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-                                        ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 

end
if  percentage>=10  and percentage<20
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[--                                       ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else
end
if  percentage>=20  and percentage<30
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[---                                      ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 

else
end

if  percentage>=30  and percentage<40
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[------                                   ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else

end
if  percentage>=40  and percentage<50
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[------------                             ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else

end
if  percentage>=50  and percentage<60
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-------------------|                     ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else

end
if  percentage>=60  and percentage<70
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-------------------|-----                ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else

end
if  percentage>=80  and percentage<90
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-------------------|-------------        ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else
end
if  percentage>=90  and percentage<100
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-------------------|------------------   ]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else
end
if  percentage>=100
then
term.clear()
term.setCursorPos( 1, 1 )
print("Please Wait While I am Processing Your Order") 
print("[-------------------|---------------------]" .. percentage .. "%")
print(" ")print(" ")print(" ")
print("I Have :   " .. num-i .. "  More Obsidian to Process ") 
else
end
sleep(1)
i = i+1
end
sleep(2)
term.clear()
term.setCursorPos( 1, 1 )
textutils.slowPrint("Ending Obsidian Production Program ... Done!")
sleep(0.2)
print ("I Just Processed: " .. num .. " Obsidian for you!")
sleep(0.2)
textutils.slowPrint("Re-launching Program...")
print ("--------------------------------------------------")


end
end


fyi
you may have noticed that you could just add a " " instead of calling loadbar. I did this because I plan on messing with this script some more and clean it up some so its not so resource intensive and will dynamically change loadbar ….just an fyi to those out there that would throw up when they see this :(/>/>

EDIT: updated ease of use and load bars