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

Need Some Help With Rs Outputs !

Started by Pixelmnkey, 27 October 2013 - 03:28 PM
Pixelmnkey #1
Posted 27 October 2013 - 04:28 PM
Hello ! I'm doing some kind of tests to new player with some questions regarding the rules and stuff, I want a computer to send a redstone pulse to a mfr bundled cable depending on the user input, working with buttons for example. Imagine the question " Can you do automining in the overworld? " and 2 buttons at the bottom, I rather use normal buttons instead of a touchscreen so, it will wait for a rs.setInput("side", true) then send a signal to the bundled cable with rs.setBundledOutput("side" colors.white"), the problem is that I can't manage to do it, here's a little program I've wrote:



while true do
    if rs.getInput("left", true) then
    rs.setOutput("back", true)
    end
  sleep(1)
  rs.setOutput("back", false)
    if rs.getInput("right", true) then
    rs.setOutput("bottom", true)
    end
  sleep(1)
  rs.setOutput("bottom", false)
end

That's for a build where each button sends a signal to a different side of the computer then it reacts according to the input, BUT I want to prevent players from clicking both buttons at the same time, any help?

If I don't explain it correct, excuse me, English isn't my native language :/
Bomb Bloke #2
Posted 27 October 2013 - 05:37 PM
rs.getInput() isn't used like that - you only specify the side, and it returns either true or false depending on what the signal on the specified side is.

Eg,

if rs.getInput("left") then
  print("I have a signal on my left side.")
else
  print("No signal to the left.")
end

Players can't push both buttons "at once", so the idea is to have the program react to the first button pushed, then wait until it's not receiving any more redstone signals before asking the next question.

-- Start out by defining a loop here that iterates once for each question.

-- Then loop until both buttons are off:
while rs.getInput("left") or rs.getInput("right") do
  os.pullEvent("redstone")  -- Pulling a redstone event makes the program wait here
end                         -- until the redstone inputs change in some way.

-- Put code to display the next question here.

os.pullEvent("redstone")  -- Wait until either button is pressed.

-- Ideally you'd put the questions/answers in a table and use that into your checks,
-- but to stick to something close to your own example:
if rs.getInput("left") then
  rs.setOutput("back", true)
  sleep(1)
  rs.setOutput("back", false)
elseif rs.getInput("right") then
  rs.setOutput("bottom", true)
  sleep(1)
  rs.setOutput("bottom", false)
end

-- Then we loop back up to the start and prepare for the next question.
Pixelmnkey #3
Posted 27 October 2013 - 06:10 PM
WoW! That actually work, thanks a lot m8!