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

[Solved]Hidden Hatch Code

Started by MutatedVirus, 03 June 2013 - 08:08 PM
MutatedVirus #1
Posted 03 June 2013 - 10:08 PM
First of all, Im really new to computer craft so Iknow my code is going to look messy, I have some basic understand in coding but this has stumpted me.

Ive been attempting to write a code that when it detects a signal input to a Computer (So i can do it VIA wireless remotes) it will do X code, I know thhe code works for opening and closing the door on it own using the computer terminal, but when I try to do it like this, it will work 2 or 3 times, then no longer work, or not work at all, I was wondering fi anyone could help me figure it out please? :)/>/>

Thanks, MV

Code:

print("Secret Door Console")
while true do
  os.pullEvent("redstone")
	if rs.getInput("left") then
	  break
	end
end
  rs.setBundledOutput("back",colours.purple)
	sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.purple)
	sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.purple)
	sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.red)
	sleep(0.5)
  rs.setBundledOutput("back",0)
while true do
  os.pullEvent("redstone")
	if rs.getInput("right") then
	  break
	end
end
  rs.setBundledOutput("back",colours.pink)
	sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.white)
	sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.white)
	 sleep(0.5)
  rs.setBundledOutput("back",0)
	sleep(0.5)
  rs.setBundledOutput("back",colours.white)
	sleep(0.5)
  rs.setBundledOutput("back",0)
Lyqyd #2
Posted 03 June 2013 - 11:33 PM
Split into new topic.
Bomb Bloke #3
Posted 04 June 2013 - 08:12 AM
There's no encompassing loops here. Your program first waits for a redstone signal to the left and then outputs purple/purple/purple/red to the rear. It then waits for a redstone signal to the right and outputs pink/white/white/white to the rear.

Then you've got no more code. The program hence ends, as there's nothing more for it to do: you've broken all your loops, so there's nothing to repeat.

Another issue is that this code doesn't account for any other methods of the door opening or closing. If there aren't any that's ok, but if there are (eg a button hidden in a wall for when you forget your remote), it may be that your code ends up waiting for a "door close" signal that'll never come 'cause the door is already closed, for example.

All this depends on the nature of your actual door construction.

Anyway, a version that'll wait for open or close signals (as opposed to open then close signals), and do so forever, would look something like:

Spoiler

print("Secret Door Console")
while true do
  os.pullEvent("redstone")

  if rs.getInput("left") then
    rs.setBundledOutput("back",colours.purple)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.purple)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.purple)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.red)
    sleep(0.5)
    rs.setBundledOutput("back",0)
  elseif rs.getInput("right") then
    rs.setBundledOutput("back",colours.pink)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.white)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.white)
    sleep(0.5)
    rs.setBundledOutput("back",0)
    sleep(0.5)
    rs.setBundledOutput("back",colours.white)
    sleep(0.5)
    rs.setBundledOutput("back",0)
  end
end

This may not work if it's essential that the "open" signal never be sent to the door when it is open, or ditto for "close".
MutatedVirus #4
Posted 04 June 2013 - 10:21 AM
I thought it would be something simple, just didn't kno the code xD Thanks, works a charm (Y) :)/>