This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
counter
Started by drakkillen, 06 September 2012 - 04:17 PMPosted 06 September 2012 - 06:17 PM
i try to figure out how to make a counter that will increase with each redstone pulse like a costumer counter in a shop there the redstone pulse is from an pressure plate problem is i cant get it to work ik how to get a value from a signal true/false and how to make a additon but i cant really make it so it will convert that true false signal to a number or varibl and i also whant it to loop without reseting the cunter and i havent figured out how to make that happen please help me iam a noob but i cant find any good tutorials:(
Posted 06 September 2012 - 06:24 PM
count = 0 --Starting value
while true do --Infinate loop
event, side = os.pullEvent() --Freeze until an event, and store as var
if event == "redstone" and side == "right" then --Change right to side to input too
count = count + 1 --count get's increased by 1
end --end if
end --End while
This would do the trick
Allso try in "ask a pro" section for questions next time
Posted 06 September 2012 - 10:22 PM
ok missed that thread but i will nexdt time thanks for the code i jsut need to see the function to learn it and i think i was on the right track
Posted 06 September 2012 - 10:46 PM
i tried to make it so i also print the value so i can display it on an monitor but it dont work at al i added
term.clear()
term.setCursorPos(1.1)
write("count: "..count)
i added it right before the end for the IF
but it dosent show anything
term.clear()
term.setCursorPos(1.1)
write("count: "..count)
i added it right before the end for the IF
but it dosent show anything
Posted 07 September 2012 - 03:11 AM
You have a period in "term.setCursorPos(1.1)" when it should be "term.setCursorPos(1,1)" – with a comma.
Posted 07 September 2012 - 11:18 AM
count = 0 e
while true do
event, side = os.pullEvent()
if event == "redstone" and side == "right" then
count = count + 1
term.clear()
term.setCursorPos(1,1)
write (count)
end
end
this is the program but all it do wene i run it is saying the program name nothing more the program is named rs and its jsut rs that is shown on the screen
while true do
event, side = os.pullEvent()
if event == "redstone" and side == "right" then
count = count + 1
term.clear()
term.setCursorPos(1,1)
write (count)
end
end
this is the program but all it do wene i run it is saying the program name nothing more the program is named rs and its jsut rs that is shown on the screen
Posted 07 September 2012 - 02:14 PM
It's waiting for a redstone signal, probably. Either that, or you're clearing the screen before it does anything. Also, please post code incount = 0 e
while true do
event, side = os.pullEvent()
if event == "redstone" and side == "right" then
count = count + 1
term.clear()
term.setCursorPos(1,1)
write (count)
end
end
this is the program but all it do wene i run it is saying the program name nothing more the program is named rs and its jsut rs that is shown on the screen
tags.
Posted 07 September 2012 - 02:31 PM
count = 0 e
while true do
event, side = os.pullEvent()
if event == "redstone" and side == "right" then
if rs.getInput("right") –Added a new if statement
count = count + 1
term.clear()
term.setCursorPos(1,1)
write (count)
end –Added end to new if statement
end
end
this is the program but all it do wene i run it is saying the program name nothing more the program is named rs and its jsut rs that is shown on the screen
It need altering. a redstone event happens 2 times. One turning on and one turning off. Therefor i changed the code in the quote
Posted 07 September 2012 - 09:52 PM
still get the same error as before :D/>/>
Posted 08 September 2012 - 09:12 PM
ithe idea for this program was from direwolf20 server lp the 2-3 last episode there he has a monitor that keep track of how many times he has used hes back door fron toor and it was rechardg that made it so i just wondred if somone could help me to make an replica with it