35 posts
Posted 26 February 2013 - 04:31 PM
title: Bundled cable input
I need help with a program im working on for a chicken farm.
print("How many chickens do you have?")
x = read()
print("How many feathers do you have?")
y = read()
print("How many eggs do you have?")
z = read()
while true do
event = os.pullEvent("redstone")
if redstone.getBundledInput("back", colors.green) then
z = z + .5
elseif redstone.getBundledInput("back", colors.brown) then
y = y + .5
elseif redstone.getBundledInput("back", colors.blue) then
x = x + .5
else
sleep(.1)
end
file = fs.open("stock","w")
file.writeLine("Chickens")
file.writeLine(x)
file.writeLine("Feathers")
file.writeLine(y)
file.writeLine("Eggs")
file.writeLine(z)
file:close()
local mon = peripheral.wrap("top")
mon.clear()
mon.setCursorPos(1,1)
mon.setTextScale(2)
mon.write("Chicken ")
mon.write(x)
mon.setCursorPos(1,2)
mon.write("Feathers ")
mon.write(y)
mon.setCursorPos(1,3)
mon.write("Eggs ")
mon.write(z)
end
the issue is the computer counts everything as eggs. Its seems my pc refuses to know the difference between bundled inputs. Also is there a way to save the data within the programs without writing the values to a different program.
309 posts
Location
Sliding between sunbeams
Posted 27 February 2013 - 03:14 AM
Are you maybe using levers to handle the bundled cable input? if that is the case and your green cable is on all the time that is the first thing thats being checked, and therefore the only thing going up.. else i dont know.
35 posts
Posted 27 February 2013 - 08:46 AM
Are you maybe using levers to handle the bundled cable input? if that is the case and your green cable is on all the time that is the first thing thats being checked, and therefore the only thing going up.. else i dont know.
I am using item detectors and even if i shut off the eggs then every time i get a feather it still reads it as an egg
2005 posts
Posted 28 February 2013 - 03:42 AM
Check your detector setup to make sure that they aren't both using green.
Alternatively, if you just connected the entire cable into the detectors, then obviously green would always be true and thus only z would update.
35 posts
Posted 28 February 2013 - 10:17 AM
Check your detector setup to make sure that they aren't both using green.
Alternatively, if you just connected the entire cable into the detectors, then obviously green would always be true and thus only z would update.
i have a different colors being plugged into each detector. However i also copy this program to a different program and only ran the brown. The results remained the same the programs still counts it as green.
1511 posts
Location
Pennsylvania
Posted 28 February 2013 - 10:49 AM
Why are you saving the data to a different file? Just use global variables (Or local)
May we see a screenshot of what your CURRENT build looks like?
You should also check to make sure the user input is a number:
variable = read()
validNum = tonumber(variable)
check = type(tonumber)
if not check == "number" then return print("Not a number") end
1054 posts
Posted 28 February 2013 - 10:55 AM
Change
redstone.getBundledInput
to
redstone.testBundledInput
eveywhere. Leave the parameters and everything else as is.
35 posts
Posted 28 February 2013 - 11:26 AM
Why are you saving the data to a different file? Just use global variables (Or local)
May we see a screenshot of what your CURRENT build looks like?
You should also check to make sure the user input is a number:
variable = read()
validNum = tonumber(variable)
check = type(tonumber)
if not check == "number" then return print("Not a number") end
I save it another file in case of server restart or will it remember where it left off?
this is my setup
Change
redstone.getBundledInput
to
redstone.testBundledInput
eveywhere. Leave the parameters and everything else as is.
When i do that it no longer counts the items/
1054 posts
Posted 28 February 2013 - 12:39 PM
Change
redstone.getBundledInput
to
redstone.testBundledInput
eveywhere. Leave the parameters and everything else as is.
When i do that it no longer counts the items/
Well,
redstone.getBundledInput takes only one parameter. So what you have now could never work as intended. My solution should work. One problem though are the elseif's because a bundled cable could have multiple colors set.
35 posts
Posted 28 February 2013 - 12:43 PM
Change
redstone.getBundledInput
to
redstone.testBundledInput
eveywhere. Leave the parameters and everything else as is.
When i do that it no longer counts the items/
Well,
redstone.getBundledInput takes only one parameter. So what you have now could never work as intended. My solution should work. One problem though are the elseif's because a bundled cable could have multiple colors set.
the issue i have with your change is that it no longer counts anything at all.
So what the basic out come of this is, that this setup will not work. Does computer craft now like bundled cable inputs lol?
2005 posts
Posted 28 February 2013 - 12:44 PM
Wait, that's right. The return from getBundledInput() is always a number, so that always returns a number, which means that if rs.getBundledInput("back", colors.green) always evaluates as a true condition. You need testBundledInput().
1054 posts
Posted 28 February 2013 - 12:53 PM
As I said. ;)/> But it doesn't seem to work for some reason. tvc, can you post your current code?
35 posts
Posted 28 February 2013 - 01:15 PM
As I said. ;)/> But it doesn't seem to work for some reason. tvc, can you post your current code?
you have it all above nothing else is in it
1054 posts
Posted 28 February 2013 - 01:17 PM
Do you understand why 'redstone.getBundledInput' could never work this way?
35 posts
Posted 28 February 2013 - 01:21 PM
Do you understand why 'redstone.getBundledInput' could never work this way?
If i understand you its because computer craft doesn't allowed more than one "if" with bundled cable. So therefor its reading the first "if" and only applying that one reguardless of the input.
1054 posts
Posted 28 February 2013 - 01:25 PM
No, that's not what's happening. I linked you to
this wiki page which shows that redstone.getBundledInput only takes one argument. Which means that what you are doing is exactly the same as:
redstone.getBundledInput("back")
which returns a number.
redstone.testBundledInput("back",colors.blue)
does what you want. It will return true if the blue color is set on the back and false otherwise.
35 posts
Posted 28 February 2013 - 01:32 PM
No, that's not what's happening. I linked you to
this wiki page which shows that redstone.getBundledInput only takes one argument. Which means that what you are doing is exactly the same as:
redstone.getBundledInput("back")
which returns a number.
redstone.testBundledInput("back",colors.blue)
does what you want. It will return true if the blue color is set on the back and false otherwise.
Ok, but when I put rs.Test… it no longer counts anything. the program runs but no data is updated
1511 posts
Location
Pennsylvania
Posted 28 February 2013 - 01:55 PM
rs.getBundledInput returns the binary number of the color it detects, it does not return the color itself. You would have to make a function to take binary numbers and turn them into the correct color. rs.testBundledInput will return true or false depending if the paramater/color is on or off.
1054 posts
Posted 28 February 2013 - 02:01 PM
Try using testBundledInput and change:
print("How many chickens do you have?")
x = read()
print("How many feathers do you have?")
y = read()
print("How many eggs do you have?")
z = read()
to:
print("How many chickens do you have?")
x = tonumber(read())
print("How many feathers do you have?")
y = tonumber(read())
print("How many eggs do you have?")
z = tonumber(read())
Also, @SuicidalSTDz: binary number doesn't seem like a good term to me (isn't every integer representable as binary anyway?). The result from getBundledInput is basically the sum of all set color values, which are powers of two.
1511 posts
Location
Pennsylvania
Posted 28 February 2013 - 02:09 PM
Try using testBundledInput and change:
print("How many chickens do you have?")
x = read()
print("How many feathers do you have?")
y = read()
print("How many eggs do you have?")
z = read()
to:
print("How many chickens do you have?")
x = tonumber(read())
print("How many feathers do you have?")
y = tonumber(read())
print("How many eggs do you have?")
z = tonumber(read())
Also, @SuicidalSTDz: binary number doesn't seem like a good term to me (isn't every integer representable as binary anyway?). The result from getBundledInput is basically the sum of all set color values, which are powers of two.
Yeah, could've phrased that a bit better I presume ;)/> "The binary equivelant of the color" seems better.
2005 posts
Posted 01 March 2013 - 12:25 PM
Replace the detectors with buttons and see if you can get it to register button presses.