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

Nonfunctional os.pullEvent and redstone code

Started by Graypup, 03 July 2013 - 04:02 PM
Graypup #1
Posted 03 July 2013 - 06:02 PM
Here is some code to create a hack-switch for any energy-net or redstone stuff, basically, place when there's redstone, break when there isn't. I just want to know why the broken code is, well, broken.
This works:
if redstone.getInput("back") then
  turtle.place()
  else
	turtle.dig()
end

while true do
  if os.pullEvent() then
	if redstone.getInput("back") then
	  turtle.place()
	  else
	  turtle.dig()
	end
  end
end
This doesn't work:


while true do
  local msg, p1, p2 = os.pullEvent()

	rsstate = rs.getInput("back")
	--debug: comment me out:
	print(rsstate)
	if rsstate == true then
	  turtle.place()
	  elseif rsstate == false then
		turtle.dig()
	  else
		error("MY REDSTONE STATE ISNT A BOOLEAN!!!1!!")
	end

end
Lyqyd #2
Posted 03 July 2013 - 06:56 PM
What's the print outputting?
Graypup #3
Posted 03 July 2013 - 06:58 PM
What's the print outputting?
Supposedly if the redstone is on or off. AFAIK it worked.
Lyqyd #4
Posted 03 July 2013 - 09:25 PM
No, not what it supposedly outputs, what it actually outputs when the code is run and the redstone state changed.