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

Redstone Frame Machine

Started by beckadd, 25 March 2018 - 05:36 AM
beckadd #1
Posted 25 March 2018 - 07:36 AM
Hey all! I've gotten great help here before, so I thought I'd ask about another issue I've encountered surrounding a different (and more complicated) program, this one controlling the movement of deployable "steps" that are moved depending on a series of conditions. There are a couple issues with my current program (seen below), primarily surrounding the redstone inputs.

Currently, the code seems to stall itself out. Nothing happens when I press the pressure plate (seen in the reference pictures, and referenced as the "source"), and the inputs are ignored.

In earlier iterations, the frames would ignore the inputs and upon starting the program would deploy and retract the frames (albeit correctly) without concern for the conditions.

What is wrong here? I've linked reference pictures and have the program below.

Reference pictures: https://imgur.com/a/rPXNp

--Current Problems:
--The program doesn't seem to care if the input and/or DoorOpen/DoorClosed conditions are met.
--The program repeats and sends itself into an error state, and resets.
--Upon changing resetDoor function conditions, the door no longer moves.
local DoorClosed = rs.testBundledInput("left",colors.purple)
local DoorOpen = rs.testBundledInput("left",colors.orange)
local input = rs.testBundledInput("left",colors.gray)
function openDoor()
  if DoorClosed == false then
	print("The door is already open.")
  else
	rs.setBundledOutput("left",colors.black+colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",colors.green)
	sleep(1)
	rs.setBundledOutput("left",0)
	sleep(1)
  end
  if DoorOpen == true then
	print("The door is now open.")
  else
	print("The program has encountered a problem. Resetting the door now.")
	resetDoor()
  end
end
function closeDoor()
if DoorOpen == false then
   print("The door is already closed.")
else
   rs.setBundledOutput("left",colors.white+colors.blue+colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",colors.blue+colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",0)
   sleep(1)
end
if DoorClosed == true then
   print("The door is now closed.")
else
   print("The program has encountered a problem. Resetting the door now.")
   resetDoor()
end
end
function resetDoor()
  repeat
	rs.setBundledOutput("left",0)
	rs.setBundledOutput("left",colors.yellow+colors.blue+colors.white)
	sleep(5)
	rs.setBundledOutput("left",colors.black+colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",0)
  until DoorClosed == true
end
while true do   --infinite loop
  if input == true and DoorClosed == true then
	openDoor()
	sleep(5)
  end
  if input == true and DoorOpen == true then
	closeDoor()
	sleep(5)
  end
  if input == false and DoorOpen == true then
	sleep(20)
	closeDoor()
  end
  if input == false and DoorClosed == true then
	sleep(1)
  end
  if DoorClosed == false and DoorOpen == false then
	resetDoor()
  end
  sleep(1)
end
SuperDyl19 #2
Posted 25 March 2018 - 11:41 PM
The variables DoorClosed, DoorOpen, and input are set at the beginning but then hold those values for the whole rest of the code. If you want the code to detect changes in the doors, you need to reset the values of these variables inside of the while loop. You may also want to use an os.pullEvent() or os.pullEventRaw() to avoid using up computing power to test for changes in redstone inputs. Here's some info on the subject: http://www.computercraft.info/wiki/Os.pullEvent http://www.computercraft.info/wiki/Os.pullEventRaw
Stekeblad #3
Posted 26 March 2018 - 07:31 AM
In function resetDoor() is DoorClosed never updated inside the loop, so if it start it never ends.
EveryOS #4
Posted 26 March 2018 - 12:33 PM

--Current Problems:
--The program doesn't seem to care if the input and/or DoorOpen/DoorClosed conditions are met.
--The program repeats and sends itself into an error state, and resets.
--Upon changing resetDoor function conditions, the door no longer moves.
local DoorClosed, DoorOpen, input
function openDoor()
  if DoorClosed == false then
	print("The door is already open.")
  else
	rs.setBundledOutput("left",colors.black+colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",colors.green)
	sleep(1)
	rs.setBundledOutput("left",0)
	sleep(1)
  end
  if DoorOpen == true then
	print("The door is now open.")
  else
	print("The program has encountered a problem. Resetting the door now.")
	resetDoor()
  end
end
function closeDoor()
if DoorOpen == false then
   print("The door is already closed.")
else
   rs.setBundledOutput("left",colors.white+colors.blue+colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",colors.blue+colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",colors.yellow)
   sleep(1)
   rs.setBundledOutput("left",0)
   sleep(1)
end
if DoorClosed == true then
   print("The door is now closed.")
else
   print("The program has encountered a problem. Resetting the door now.")
   resetDoor()
end
end
function resetDoor()
  repeat
	rs.setBundledOutput("left",0)
	rs.setBundledOutput("left",colors.yellow+colors.blue+colors.white)
	sleep(5)
	rs.setBundledOutput("left",colors.black+colors.red+colors.green)
	sleep(1)
	rs.setBundledOutput("left",0)
  until DoorClosed == true
end
while true do   --infinite loop
  DoorClosed = rs.testBundledInput("left",colors.purple)
  DoorOpen = rs.testBundledInput("left",colors.orange)
  input = rs.testBundledInput("left",colors.gray)
  if input == true and DoorClosed == true then
	openDoor()
	sleep(5)
  end
  if input == true and DoorOpen == true then
	closeDoor()
	sleep(5)
  end
  if input == false and DoorOpen == true then
	sleep(20)
	closeDoor()
  end
  if input == false and DoorClosed == true then
	sleep(1)
  end
  if DoorClosed == false and DoorOpen == false then
	resetDoor()
  end
  sleep(1)
end
SuperDyl19 #5
Posted 27 March 2018 - 03:00 AM
Your resetDoor() function doesn't change the value of DoorClosed, so your function probably times out.