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

Making if read() or rs.getInput() then

Started by nitan, 07 January 2014 - 02:58 PM
nitan #1
Posted 07 January 2014 - 03:58 PM
Hi ComputerCraft.

And thanks for this awesome mod :)/>

So, to my question.. I currently have password coded door, that opens for 3 seconds when read() is filled and "entered", and this works perfectly.

but as this should only work from outside to inside, i added a button next to the computer, and wants that to have same effect, so opening the door for 3 seconds.

but as read() is doing a sort of halt on the program, how can you bypass that ?

if its possible ofcourse :)/>

Thank you very much in advance.

Regards
Victor
CometWolf #2
Posted 07 January 2014 - 04:35 PM
The easiest option would obviously be to just connect your button to the redstone controlling the door. If you want to bypass the system halt caused by read() you'll have to program your own read function using os.pullEvent. It's quie simple once you understand the concept of it.
http://computercraft...ki/Os.pullEvent
Basically what you want is to capture every char event and use that as input which you also render on screen, then when you get a redstone event, you check the side the button is connected to and react accordingly. If you're having trouble you should have a look at the actual read function, it's made the same way. Or better yet, just copy and modify it as needed.
Edited on 07 January 2014 - 03:38 PM
LBPHacker #3
Posted 07 January 2014 - 05:10 PM
Or you can use the parallel API. More lag, less code:
local function waitForRedstone()
    -- some code that processes the redstone signals
end

local function waitForRead()
    local input = read("*")
    -- some code that processes the user input
end

parallel.waitForAny(waitForRedstone, waitForRead)
-- ^ the call is for parallel.waitForAny, not for any of the other two functions
Edited on 07 January 2014 - 04:10 PM