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

Getting a program to print text with redstone inputs

Started by Zelpa, 29 July 2012 - 06:08 AM
Zelpa #1
Posted 29 July 2012 - 08:08 AM
I need a program that will print text when redstone is input and print another text when a redstone signal isn't input but I'm not sure how to go about this, I was trying to use else but it didn't work.
BigSHinyToys #2
Posted 29 July 2012 - 08:42 AM
This should do it
Spoiler

local sSide = "left" -- the side on input
local pState = false -- this shows if it was on before so er dont have to print again
while true do -- start of a loop
    local e,e1,e2,e3,e4,e5 = os.pullEvent() -- waits for somthign to happen
    if e == "redstone" and rs.getInput(sSide) and not pState then -- checks if somthing redstone has changes also checks if it was the side we selected an cheches wether it was on bofore
	    print(sSide.." Turned On") -- prints to screen
	    pState = true -- stores its previous state
    elseif e == "redstone" and not rs.getInput(sSide) and pState then  -- checks if somthing redstone has changes also checks if it was the side we selected an cheches wether it was on bofore
	    print(sSide.." Turned Off") -- prints to screen
	    pState = false -- stores its previous state
    end -- end of IF statent
end -- end of while loop
Malakai030 #3
Posted 25 August 2012 - 10:09 PM
nice, clean code :D/>/> I'd love to have more like this

Do you happen to have a version that doesn't work like a latch, but just accepts a button signal to start the wished code?
BigSHinyToys #4
Posted 26 August 2012 - 12:59 AM
this is a striped version replace the test function with the code you want to run.
Spoiler

function test()
    print("testring one two three")
end
local sSide = "left" -- the side on input
while true do -- start of a loop
    local e,e1,e2,e3,e4,e5 = os.pullEvent() -- waits for somthign to happen
    if e == "redstone" and rs.getInput(sSide) then -- checks if somthing redstone has changes also checks if it was the side we selected an cheches wether it was on bofore
		    test()-- Put your function here
    end -- end of IF statent
end -- end of while loop
Malakai030 #5
Posted 29 August 2012 - 02:52 PM
Phat Thanks! It works great!

I use that code for a door, which opens by inserting a certain musik disk and hitting a button :)/>/>


Thanks again.