1 posts
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.
992 posts
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
6 posts
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?
992 posts
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
6 posts
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.