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

help with counter

Started by korupt_virus, 12 April 2012 - 03:17 AM
korupt_virus #1
Posted 12 April 2012 - 05:17 AM
http://pastebin.com/DFaTnew1 keeps throwing bad argument: string expected got nil. Please help with this as this is a great part of my base.
virtualayu #2
Posted 12 April 2012 - 07:44 AM
first :

redstone.setBundledOutput("back", colors.white,true)
sleep(.5)
redstone.setBundledOutput("back", colors.white,false)

this is not how bundled cables works…
try :

rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white,) – this is how set off a bundled cable…

you can't say true or false… it's not that simple^^
and use rs.set or rs.get is simple than redstone.set ….

in your first line why did you wrote uum = "uum" ??? no need… you say uum = 0 if the file don't exist and say uum = tonumber(count.readline()) if it does… so why did you declare it in the first place?? (thats not a big deal but is 100% useless)

in order to be clear please in an "if" write the variables in the right order… "if i == uum then" not "if uum == i then" (again not a big deal it don't change the program but it's easyer to read ^^)



I assume that your program is called "get", am i right?
don't end your program by calling it again… just make a loop ^^
after getting values in your file and closed it, put this : while true do
and at the end put an end to close the loop

so the correct code for all of this should be :
Spoilerif fs.exists("counter.txt") == false then
count = fs.open("counter.txt", "w")
uum = 0
stacks = uum / 64
dc = stacks / 54
count.writeLine(uum)
count.writeLine(stacks)
count.writeLine(dc)
count.close()
end
count = fs.open("counter.txt", "r")
uum = tonumber(count.readLine())
stacks = tonumber(count.readLine())
dc = tonumber(count.readLine())
count.close()
while true do
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("What would you like to withdrawl?")
uumm = "uum"
stackss = "stacks"
dcc = "double chests"
i = read()
if i == uumm then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How much uum?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - 1
uum = uum - 1
end
end
if i == stackss then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How many stacks?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - (1 / 64)
uum = uum - 1
end
end
if i == dcc then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How many chests?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - (1 / (64 / 54))
uum = uum - 1
end
end
count = fs.open("counter.txt", "w")
count.writeLine(uum)
count.writeLine(stacks)
count.writeLine(dc)
count.close()
end
Luanub #3
Posted 12 April 2012 - 07:49 AM
first :

redstone.setBundledOutput("back", colors.white,true)
sleep(.5)
redstone.setBundledOutput("back", colors.white,false)

this is not how bundled cables works…
try :

rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white,) – this is how set off a bundled cable…

you can't say true or false… it's not that simple^^
and use rs.set or rs.get is simple than redstone.set ….

in your first line why did you wrote uum = "uum" ??? no need… you say uum = 0 if the file don't exist and say uum = tonumber(count.readline()) if it does… so why did you declare it in the first place?? (thats not a big deal but is 100% useless)

in order to be clear please in an "if" write the variables in the right order… "if i == uum then" not "if uum == i then" (again not a big deal it don't change the program but it's easyer to read ^^)



I assume that your program is called "get", am i right?
don't end your program by calling it again… just make a loop ^^
after getting values in your file and closed it, put this : while true do
and at the end put an end to close the loop

so the correct code for all of this should be :
Spoilerif fs.exists("counter.txt") == false then
count = fs.open("counter.txt", "w")
uum = 0
stacks = uum / 64
dc = stacks / 54
count.writeLine(uum)
count.writeLine(stacks)
count.writeLine(dc)
count.close()
end
count = fs.open("counter.txt", "r")
uum = tonumber(count.readLine())
stacks = tonumber(count.readLine())
dc = tonumber(count.readLine())
count.close()
while true do
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("What would you like to withdrawl?")
uumm = "uum"
stackss = "stacks"
dcc = "double chests"
i = read()
if i == uumm then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How much uum?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - 1
uum = uum - 1
end
end
if i == stackss then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How many stacks?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - (1 / 64)
uum = uum - 1
end
end
if i == dcc then
term.clear()
term.setCursorPos(1,1)
print(" uum : "..uum)
print(" stacks : "..stacks)
print(" double chests : "..dc)
print("How many chests?")
x = tonumber(read())
if x > 0 then
rs.setBundledOutput("back", colors.white)
sleep(.5)
rs.setBundledOutput("back", rs.getBundledInput("back") - colors.white)
x = x - (1 / (64 / 54))
uum = uum - 1
end
end
count = fs.open("counter.txt", "w")
count.writeLine(uum)
count.writeLine(stacks)
count.writeLine(dc)
count.close()
end

The real way/best way to work bundled cables is…


to turn on - turns on white
c = colors.combine( c, colors.white )
rs.setBundledOutput("back", c )

to add more - combined with the above with have white/orange on
c = colors.combine( c, colors.orange )
rs.setBundledOutput("back", c )

and to turn off  - white off/ orange on
c = colors.subtract( c, colors.white )
rs.setBundledOutput("back", c )

type help redpower from a console for more info
Edited on 12 April 2012 - 06:03 AM
virtualayu #4
Posted 12 April 2012 - 04:50 PM
yes if you use multiple colors but in this case he use only one color and his program is very simple.
so he don't have to make variables with conbined colors…