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

Need some help with Redstone inputs please :)

Started by Bmasta8899, 23 July 2012 - 09:07 PM
Bmasta8899 #1
Posted 23 July 2012 - 11:07 PM
Hey Guys I am attempting to create a door that flush with the wall in my room, i can open it useing the command on the console its self but im having trouble getting it to open a from the inside when i press the button


shell.run("clear")
print("Window's 7")
print("Piratebay edition")
print()
print("What would you like to do ben?")

input = read()

sc = "oldpeopleburning"

if input == sc then
print("Opening Private safe…")
sleep (1.0)
rs.setBundledOutput("bottom", colors.magenta)
sleep(0.5)
rs.setBundledOutput("bottom", colors.white)
sleep(10.0)
rs.setBundledOutput("bottom", colors.orange)
sleep(0.5)
rs.setBundledOutput("bottom", colors.black)
end

if rs.testInput("back") == true then
print("Opening Private safe…")
sleep (1.0)
rs.setBundledOutput("bottom", colors.magenta)
sleep(0.5)
rs.setBundledOutput("bottom", colors.white)
sleep(10.0)
rs.setBundledOutput("bottom", colors.orange)
sleep(0.5)
rs.setBundledOutput("bottom", colors.black)
end

shell.run("startup")


(Im useing RS latches and wireless RS to apply power to the door at the time it needs is)
Bmasta8899 #2
Posted 24 July 2012 - 03:38 AM
Bump really need a hand, please help if u can
Noodle #3
Posted 24 July 2012 - 03:42 AM
1: For that empty print make it print(" ")
2: What is your error? - IF there is one.
Bmasta8899 #4
Posted 24 July 2012 - 07:20 AM
Thank you for replying, even tho i press the button it wont run though the function
KaoS #5
Posted 24 July 2012 - 07:28 AM
you are calling the read() function, the program then stops and waits for you to enter your password so it won't check the back for redstone input until you have entered a password
Bmasta8899 #6
Posted 24 July 2012 - 07:30 AM
ohhhhh ok, How would i fix that? Put the input before the read() function?
Darky_Alan #7
Posted 24 July 2012 - 07:36 AM
ohhhhh ok, How would i fix that? Put the input before the read() function?

Make the whole thing a function, I didin't proof read your code but just add
at the top:
function read()
–then at the bottom add
end
read()
Bmasta8899 #8
Posted 24 July 2012 - 08:41 AM
You lost me a bit, i added that but still nothing….
Darky_Alan #9
Posted 24 July 2012 - 08:44 AM
You lost me a bit, i added that but still nothing….

Ugh let me space out your code and proof read it, I'll try to hand you a fix.

Also question, why are you shell running startup at the end of the code?
KaoS #10
Posted 24 July 2012 - 08:48 AM
neither of those options will work, you will either have to have 2 separate computers, one for password input and one to listen for redstone input or develop a new read function that pulls events to get your key presses for a password and simultaneously checks for a redstone event, sorry but that's the only way to get this working
Darky_Alan #11
Posted 24 July 2012 - 09:05 AM
neither of those options will work, you will either have to have 2 separate computers, one for password input and one to listen for redstone input or develop a new read function that pulls events to get your key presses for a password and simultaneously checks for a redstone event, sorry but that's the only way to get this working
Right, you can't have more than one loop running at a time.
Noodle #12
Posted 24 July 2012 - 09:09 AM
Yes you can.. Parallel api.
Tutorial
Bmasta8899 #13
Posted 24 July 2012 - 10:09 AM
How would i implement that? haha once again sorry, Im new, this was like my 3rd attempt at writing a program haha
Bmasta8899 #14
Posted 24 July 2012 - 10:11 AM
and im running startup at the end beacuse that's the name of the file and it restarts the programs after i A: type in a password or B: (hopefully haha) run the if statment with the Rs input
Noodle #15
Posted 24 July 2012 - 10:12 AM
Make 2 functions
add While true loop at the end.

function input()
   -- Input (read) sht here --
end
function rs()
   -- Redstone if's here --
end
while true do
   parallel.waitForAny(input, rs)
end

EDIT: 400th post.
Bmasta8899 #16
Posted 24 July 2012 - 10:15 AM
Gottcha ill go try that, Gratz on the 400th post
Bmasta8899 #17
Posted 24 July 2012 - 10:27 AM
[attachment=339:Untitled.jpg]Here Is what i got
KaoS #18
Posted 24 July 2012 - 10:28 AM
still won't work… parallel api is complicated, I don't understand it fully but it will wait for the read() function to close
BigSHinyToys #19
Posted 24 July 2012 - 10:38 AM
still won't work… parallel api is complicated, I don't understand it fully but it will wait for the read() function to close
just because something is complicated doesn't mean it wont work.
it is plausible to make two separate loops (coroutine) run at the same time(well a microsecond gap)
look at my program here specifically the WIFI section
http://www.computercraft.info/forums2/index.php?/topic/2730-cc13-bench-v09-multi-perpous-testing-utility/
it is running a read while listening for rednet messages.
BigSHinyToys #20
Posted 24 July 2012 - 10:54 AM
This should do the trick
Spoiler

local password = "oldpeopleburning"
local function OpenDoor()
    print("Opening Private safe...")
    sleep (1.0)
    rs.setBundledOutput("bottom", colors.magenta)
    sleep(0.5)
    rs.setBundledOutput("bottom", colors.white)
    sleep(10.0)
    rs.setBundledOutput("bottom", colors.orange)
    sleep(0.5)
    rs.setBundledOutput("bottom", colors.black)
end
local function ConsolOpen()
    while true do
	    term.clear()
	    term.setCursorPos(1,1)
	    print("Window's 7")
	    print("Piratebay edition")
	    print("")
	    print("What would you like to do ben?")
	    input = read()
	    if input == password then
		    OpenDoor()
	    end
    end
end
local function ManualOpen()
    while true do
	    local e = os.pullEvent()
	    if e == "redstone" and rs.getInput("back") then
		    OpenDoor()
	    end
    end
end
rs.setBundledOutput("bottom", colors.black)
while true do
   parallel.waitForAll(ConsolOpen,ManualOpen)
end

it is untested
KaoS #21
Posted 24 July 2012 - 11:02 AM
not sure, but as before mentioned I am not very experienced with the parallel api, please post if this works as it will explain a lot
Bmasta8899 #22
Posted 24 July 2012 - 07:00 PM
Going to try now, Thanks a ton bro
Bmasta8899 #23
Posted 24 July 2012 - 07:05 PM
<3 u forever bro that did it!!!!!!!!
KaoS #24
Posted 26 July 2012 - 02:16 PM
Hmm…. that means that lua does support it, when I said that I do not understand it and that it doesn't work I did not mean that ignorance=lack of functionality, apologies for being unclear, it is just that my impression of the parallel api is that it executes lines of code from each function but when it gets to a pullevent etc it waits for it to close before executing the next line of either function, it seems that I was wrong, I thought that the read() function would pause it.

anyways, thanks for the info, this could assist me greatly