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

need help with a program...

Started by ComputerCrafter, 07 February 2013 - 04:36 PM
ComputerCrafter #1
Posted 07 February 2013 - 05:36 PM
Title: need help with a program…

How would I detect a redstone pulse with a computer? I want to detect the pulse and do something else, so what would be the code for this?
tesla1889 #2
Posted 07 February 2013 - 06:53 PM

local event,side = os.pullEvent("redstone")
if (side == the_side_you_want) then
--code
end
remiX #3
Posted 07 February 2013 - 07:13 PM
I don't think the redstone event returns the side… At least it didn't last time I checked.
theoriginalbit #4
Posted 07 February 2013 - 07:40 PM

local event,side = os.pullEvent("redstone")
if (side == the_side_you_want) then
--code
end
I don't think the redstone event returns the side… At least it didn't last time I checked.
remiX is correct, there is no side returned with the event. http://computercraft.info/wiki/Os.pullEvent#Event_types

So it would be required to use the RedStone API to detect the desired side.


os.pullEvent("redstone")
if rs.getInput("left") then -- where left is the side you want
  print("Left is active")
else
  print("Some other side triggered")
end
tesla1889 #5
Posted 07 February 2013 - 08:23 PM
oh. whoops. i kinda figured that because rednet, disk, modem, etc. have side parameters, redstone would have one too
theoriginalbit #6
Posted 07 February 2013 - 08:30 PM
oh. whoops. i kinda figured that because rednet, disk, modem, etc. have side parameters, redstone would have one too
Yeh i thought so at first too. but it doesn't… I think it should have one though…
ComputerCrafter #7
Posted 08 February 2013 - 06:01 AM
Ok, for some of you who are familiar with feed the beast/tekkit, I am making a bar, where, what I want to do is have the customer throw in their payment, and that goes into an item detector, which checks to see if it is a diamond. If it is, then it sends a redstone signal to the left of it. What I want to do is have the computer check if it recieved the signal and tell the customer that it recieved their payment and their beer will be right out. So, how could this work? I could post my code as it is for you if you would like.
theoriginalbit #8
Posted 08 February 2013 - 06:12 AM
I know you are new and can't post topics, we hear that reason all the time, but if you read the bold text in this stickie, which is forum guidelines then you would have been lead to this stickie, which is in this very "Ask a Pro" section which you posted!
ComputerCrafter #9
Posted 08 February 2013 - 06:20 AM
I know you are new and can't post topics, we hear that reason all the time, but if you read the bold text in this stickie, which is forum guidelines then you would have been lead to this stickie, which is in this very "Ask a Pro" section which you posted!

I did before, I was just making myself more clear on what I wanted to do, as I was the original poster of this thread and I was updating, trying to make it so you guys would know what I am having problems with :)/> I was in a hurry when I posted this so I thought you might be confused. Quick recap: Original poster, updating, more clear.
theoriginalbit #10
Posted 08 February 2013 - 06:23 AM
I did before, I was just making myself more clear on what I wanted to do, as I was the original poster of this thread and I was updating, trying to make it so you guys would know what I am having problems with :)/> I was in a hurry when I posted this so I thought you might be confused. Quick recap: Original poster, updating, more clear.
Oh I get ya now reading that question again. oops. It really seemed like a new question… sorry… lets put it down to the fact its 4am and I'm tired :P/>

To answer your extension,
It requires the item detector being setup correct, but using the method I posted earlier it would work fine, as it would wait for the redstone pulse from the item detector.

EDIT: If you wanted some kind of timeout (incase someone walks away) you could do this,

local timeout = os.startTimer(10) -- where 10 is the seconds you wish to set for the timeout
while true do
  local event, param = os.pullEventRaw()
  if event == "redstone" and rs.getInput("left") then -- where left is the side the item detector is on
    print("Payment received. Thank you.") 
  elseif event == "timer" and param == timeout then
    print("Sorry you did not enter money in enough time")
  end
end
ComputerCrafter #11
Posted 08 February 2013 - 06:30 AM
Ok, thanks :)/> Sorry to be so harsh, hopefully I didnt come out rude. Some of this comes easily to me, because I know javascript, and the two are similar. I get stuck on the harder things that lua has. Well, thanks for your help! hopefully I can get it up and running, and maybe I will take a video of it. Who knows? :P/>

EDIT: So what about the bottom? Would I say:

if event == "redstone" and rs.getInput("bottom") then

??