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

I need a program that detects and counts redstone pulses

Started by candycool1234, 20 September 2012 - 09:13 PM
candycool1234 #1
Posted 20 September 2012 - 11:13 PM
Ive tryed and tryed i cant get it is there a program that can help me plz i want it strate the program i need counts redstone pules plz helppp
Noodle #2
Posted 20 September 2012 - 11:17 PM
Please go to the wiki for this stuff, a LOT of answers will be there. Also, shouldn't this be in Ask a Pro?
count = 0
if rs.getInput("side") then
  count = count + 1
end
candycool1234 #3
Posted 20 September 2012 - 11:18 PM
will this work

print("Computers made today")

count = 0
if rs.getInput("back") then
count = count + 1
end
Cranium #4
Posted 20 September 2012 - 11:23 PM
Nope. That will run once, then stop.

local pulse = 0
while true do
local event,p1 = os.pullEvent()
if event == "redstone" then
pulse = pulse + 1
end
end
This will constantly run, and wait for a redstone pulse. You would need to add other code within the while loop for anything to run though.

Edit: And please, post questions in the Ask a Pro section. That's what it is there for.
candycool1234 #5
Posted 20 September 2012 - 11:28 PM
srry only joined for help im srry didnt know will this work?

print("computers made so far")

local pulse = 0
while true do
local event,p1 = os.pullEvent()
if event == "redstone" then
pulse = pulse + 1
end
end

i need a counter imma use a detector and it will send a pulse after each computer
befor shiped 2 my shop
Noodle #6
Posted 20 September 2012 - 11:30 PM
srry only joined for help im srry didnt know will this work?

print("computers made so far")

local pulse = 0
while true do
local event,p1 = os.pullEvent()
if event == "redstone" then
pulse = pulse + 1
end
end

i need a counter imma use a detector and it will send a pulse after each computer
befor shiped 2 my shop
Yes it will.
MysticT #7
Posted 20 September 2012 - 11:34 PM
Well, that would work, but it will say "computers made so far" and then keep looping and do nothing else (just counting changes in redstone).
To count pulses, you need something like this:

local sInputSide = "left" -- change to the side of the redstone input (where the wire is)

local count = 0
local lastInput = false

while true do
  os.pullEvent("redstone")
  local input = rs.getInput(sInputSide)
  if input ~= lastInput then
    if input then
	  count = count + 1
	  print(count, " computers made so far.")
    end
    lastInput = input
  end
end
candycool1234 #8
Posted 20 September 2012 - 11:35 PM
it worked untill the pulses started
candycool1234 #9
Posted 20 September 2012 - 11:37 PM
print("Computers Made so far")

local sInputSide = "back"

local count = 0
local lastInput = false

while true do
os.pullEvent("redstone")
local input = rs.getInput(sInputSide)
if input ~= lastInput then
if input then
count = count + 1
print(count, " computers made so far.")
end
lastInput = input
end
end

i think this will work
MysticT #10
Posted 20 September 2012 - 11:39 PM
print("Computers Made so far")

local sInputSide = "back"

local count = 0
local lastInput = false

while true do
os.pullEvent("redstone")
local input = rs.getInput(sInputSide)
if input ~= lastInput then
if input then
count = count + 1
print(count, " computers made so far.")
end
lastInput = input
end
end

i think this will work
Well, yes, is the code I posted with a line added at the start :)/>/>
Cranium #11
Posted 20 September 2012 - 11:45 PM
Well, we are glad that you joined, we just like questions in a certain area so it is seen by the right people.
Not sure what you are trying to do. Are you trying to have a program print the number of items crafted when it is told how many pulses?

local pulse = 0
while true do
term.clear()
term.setCursorPos(1,1)
write("Computers made so far: ")
local event,p1 = os.pullEvent()
if event == "redstone" then
pulse = pulse + 1
term.clear()
term.setCursorPos(1,1)
write("Computers made so far: "..pulse)
end
end
Here's what I have so far.
candycool1234 #12
Posted 20 September 2012 - 11:51 PM
yes i need it to show how many items with redstone pulses lol
candycool1234 #13
Posted 20 September 2012 - 11:54 PM
no teh code doe not work it says bio:206: {string "startup"}:15: '<eof>' expected
Cranium #14
Posted 20 September 2012 - 11:57 PM
What code do you have? The ones posted here should work.
candycool1234 #15
Posted 21 September 2012 - 12:03 AM
ok i got it 2 work i miss spelled then lol now itstarts and when i put a pulse 2 it it sas
startup:10: bad argument: string expected, got nil

no im useing mistics
candycool1234 #16
Posted 21 September 2012 - 12:05 AM
btw im useing tekkit and this is counting the items tru the transport pipe 2 store it send apulse to the computer i need it 2 read how many computers go tru 2 store
candycool1234 #17
Posted 21 September 2012 - 12:07 AM
will the counter pulsedesplay a number that has been pulsedetected becuse tahts what i need
candycool1234 #18
Posted 21 September 2012 - 12:13 AM
lol cranium thx for the help and thx 2 mistic i can program door usernames locks and alrms im trying 2 learn all of computer craft becuse the alowance 2imagin is limet less :)/>/>

i didnt mean thx 2 mistinc i mean thx 2.
candycool1234 #19
Posted 21 September 2012 - 12:18 AM
i think the line print(count, " Computers madeso far") might be teh problem
Cranium #20
Posted 21 September 2012 - 12:27 AM
I'm sorry, I can't keep reading your posts. Could you please write your words like they are spelled in the dictionary? It hurts my eyes to look at that and makes it hard to take you seriously. I can understand if you post it once or twice, but to continue writing like you are texting makes me want to ignore these posts. Text speak is not a valid language.
candycool1234 #21
Posted 21 September 2012 - 12:33 AM
cranium ur code doesnt work ither
candycool1234 #22
Posted 21 September 2012 - 12:35 AM
im sorry i will speak proper english can you check your program?
Cranium #23
Posted 21 September 2012 - 12:36 AM
It should work. What kind of error are you getting?
MysticT #24
Posted 21 September 2012 - 12:36 AM
I agree with Cranium.
For the error check if you wrote sInputSide right both times.
candycool1234 #25
Posted 21 September 2012 - 12:38 AM
Cranium it says
bios:206:{string "count"}:1: '<name>' expected
do you know what this means?
Cranium #26
Posted 21 September 2012 - 12:42 AM
That means line 1 has a syntax error. Did you add anything to the code I posted?
candycool1234 #27
Posted 21 September 2012 - 12:43 AM
.. mystic i failed XD i did sinputSide
and sInputSide lol if ixed it. It is now working :)/>/> thx for your help you two if u need help with alarm code lock username and password doors ill make you one i owe you two big time if i have works with out spaces its becuse my space bar is glitchy
candycool1234 #28
Posted 21 September 2012 - 12:44 AM
Cranium no line one is exactly same
Cranium #29
Posted 21 September 2012 - 12:46 AM

local pulse = 0
Should not throw any error whatsoever.
candycool1234 #30
Posted 21 September 2012 - 12:47 AM
ok fixed it there was a extra space… but im gonna stick with mystics it looks cooler thanks you two
kendfinger #31
Posted 27 September 2012 - 01:09 AM
Can somebody please make a modification to this code to make it print to monitor. I could do it but face it, I'm lazy. :P/>/>
MysticT #32
Posted 27 September 2012 - 02:35 AM
Can somebody please make a modification to this code to make it print to monitor. I could do it but face it, I'm lazy. :D/>/>
We don't like lazy people here, so go away.

Just kidding :P/>/>
It's really easy to do it. These are the easier ways:
1. Run the program using monitor <side of the monitor> <program name>.
2. Add this at the top of the code:

term.redirect(peripheral.wrap("<side of the monitor>"))