This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Emitting Redstone Signal Based On Chest Inventory
Started by lando, 31 July 2013 - 10:41 AMPosted 31 July 2013 - 12:41 PM
Hello, I am trying to set up something in a player owned shop where if someone buys an item (ie. a stick) the computer will emit a redstone signal for (x) time and then shut off based on how many items are in the chest. My idea is to fill a chest with sticks and sell them so that when a player buys one a mob spawner will turn on for 5 minutes or so, then shut off and wait for the next purchase.
Posted 31 July 2013 - 02:49 PM
Split into new topic.
You might be able to use a trapped chest and a comparator, but that will obviously have a relatively low resolution for the quantity in the chest. If you need finer detail, you'd have to use something like OpenCCSensors or, I suppose, OpenPeripheral or MiscPeripherals.
You might be able to use a trapped chest and a comparator, but that will obviously have a relatively low resolution for the quantity in the chest. If you need finer detail, you'd have to use something like OpenCCSensors or, I suppose, OpenPeripheral or MiscPeripherals.
Posted 31 July 2013 - 03:05 PM
I only need to know whether the chest is full or not. I can avoid needing to know the exact quantity in the chest at all times. And how would I put a 300 second timer on a comparator?
Posted 31 July 2013 - 03:19 PM
I only need to know whether the chest is full or not. I can avoid needing to know the exact quantity in the chest at all times. And how would I put a 300 second timer on a comparator?
Dear Lando,
You can either use a Gate Reader or a Gate Reader Turtle. This is what the code would look like
data = m.get() --#This will fetch you your information
if data["Chest full"] then --#If the chest is full, it will proceed
rs.setOutput(side, x) --#Instead of side and x, fill in the side you want to output to and for how long in SECONDS
end
If you want to use this in an infinite loop, use this:
while true do
data = m.get()
if data["Chest full"] then
rs.setOutput(side, x)
end
end
Posted 31 July 2013 - 03:31 PM
Thank you very much. I will try this and let you know if I have any problems.
Posted 31 July 2013 - 06:16 PM
Sorry I am very new to this. I copied your code for the infinite loop exactly and I get the error "spawn:2: attempt to index ? (a nil value)."
Is there anything else I need to add?
My current setup is:
chest-gatereader-computer
Is there anything else I need to add?
My current setup is:
chest-gatereader-computer
Posted 31 July 2013 - 06:48 PM
Sorry I am very new to this. I copied your code for the infinite loop exactly and I get the error "spawn:2: attempt to index ? (a nil value)."
Is there anything else I need to add?
My current setup is:
chest-gatereader-computer
EDIT: The redstone signal has to obviously reset and my code previously was incorrect about that..
I'm very sorry, I forgot to wrap the peripheral. That's where the letter 'm' comes from in m.get(). I'll fix it:
m = peripheral.wrap(side) --#please enter the side before you run the code and remove comments
data = m.get()
if data["Chest full"] then
rs.setOutput(side, true) --#please enter side before you run the code and remove comments
sleep(x) --#enter time in seconds
rs.setOuput(side, false)
end
Posted 31 July 2013 - 07:10 PM
Hopefully this is my last question.
EDIT: Changed code to match yours. Same error.
Currently my code looks like this:
I am getting the error "too long without yielding."
EDIT: Changed code to match yours. Same error.
Currently my code looks like this:
while true do
m = peripheral.wrap("left")
data = m.get()
if data["Chest full"] then
rs.setOutput("right", true)
sleep(10)
rs.setOutput("right", false)
end
end
I am getting the error "too long without yielding."
Posted 31 July 2013 - 07:27 PM
Hopefully this is my last question.
EDIT: Changed code to match yours. Same error.
Currently my code looks like this:while true do m = peripheral.wrap("left") data = m.get() if data["Chest full"] then rs.setOutput("right", true) sleep(10) rs.setOutput("right", false) end end
I am getting the error "too long without yielding."
Well, that's an error that's very easily fixed. What that error means is that the computer is doing something too long and actually achieving nothing. So if you put a sleep outside the if-statement. You'll be fine. Sorry for the some kind of blurry help. It's a combination of alcohol and tiredness. This should work:
while true do
m = peripheral.wrap("left")
data = m.get()
if data["Chest full"] then
rs.setOutput("right", true)
sleep(10)
rs.setOutput("right", false)
end
sleep(1)
end
Posted 31 July 2013 - 07:44 PM
Thanks for the help! No more errors. Only problem now is I'm not getting a redstone signal..
Posted 31 July 2013 - 07:55 PM
Thanks for the help! No more errors. Only problem now is I'm not getting a redstone signal..
It will ONLY put out a redstone signal when the chest is full. I can't really check for you, because I'm not at home, but you can do some research for yourself on the interwebs. If there is something wrong, it is in that if-statement.
Posted 31 July 2013 - 08:58 PM
OK. I will take a look around. Let me know if you figure it out though. Thanks.
Posted 01 August 2013 - 10:51 AM
Alright, so I have searched and searched online to try and find the solution. Unfortunately there are no tutorials, videos, or any information on linking chests to gate readers. Are we sure that "Chest full" is the correct term to use in the if statement? Because I have a hunch that it is not putting out a signal because it doesn't know what it is looking for.
Posted 01 August 2013 - 02:12 PM
Alright, so I have searched and searched online to try and find the solution. Unfortunately there are no tutorials, videos, or any information on linking chests to gate readers. Are we sure that "Chest full" is the correct term to use in the if statement? Because I have a hunch that it is not putting out a signal because it doesn't know what it is looking for.
That was the weak spot I pointed out. I'm downloading FTB Unleashed right now and trying to figure it out for you. I have some diagnostic code for you so you can test if the gate reader is getting the information right:
m = peripheral.wrap("left")
data = m.get()
for i,j in ipairs(data) do
print(tostring(i)..": "..tosting(j))
end
If you run this code it will return all values in a table. If you see Chest full spelled in a different way, please correct that in the code I gave you. This is the best I can help you. I'm gonna run some tests in my own FTB client and see if I can help you.
EDIT: FOUND IT!The data is not call "Chest full", it is called "Inventory Full". If you type 'Inventory Full' (without quotation marks) into the place where 'Chest Full' was, then you'll be alright.
Posted 01 August 2013 - 03:03 PM
THANK YOU SO MUCH! You have been very helpful.