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

Trouble with bundled cable or "redstone" event

Started by mayaman79, 07 March 2012 - 01:20 PM
mayaman79 #1
Posted 07 March 2012 - 02:20 PM
Hey guys!

Just want to say im so in the air over this mod hitting the tekkit package, and now starting to get the basics down, but here i get a wierd one(atleast for me ):


Code:



while true do

event = os.pullEvent()

if event == "key" then
  
   input = read()
  
   if input == "sesam" then
	  rs.setOutput("back", true)
	  sleep(5)
	  rs.setOutput("back", false)
  
   elseif input == "stop" then
	  print("Stopping the computer...")
	  sleep(1)
	  os.shutdown()
   end

elseif event == "redstone" then

	  if rs.testBundledInput("left", colours.red) then
		 rs.setOutput("back", true)
		 sleep(5)
		 rs.setOutput("back", false)

	  else
		 print("no input")
	  end


end

sleep(1)
end


Code ends



Question: Why doesnt my "elseif event == "redstone" section work ? my "Key" event works flawlessly.


This code doesn't give me any errors what so ever. but it doesnt do anything either. Its like it doesnt "find" my event for the incoming redstone signal 1

Its going like this for the "input":

torch->redwire->red insulated wire->bundledcable->COMPUTER



This is a easy little program for a door code on the outside. and a button on the inside, hence the "redstone" event(button)


Edit: I've seen there was a bug with bundled before, and i renamed the redpower file with a a1-added to the name
now that i did that, i can get a other one to work, with


if rs.testBundledInput("left", colours.blue) then
print("works")
end


edit: Learning to follow rules, and making it all a bit nicer
Advert #2
Posted 07 March 2012 - 04:00 PM
Hey mayaman79, in the future, could you please read the stickies?

When you format your code nicely, It's much easier to read over it on the forums, rather than having to copy/paste it.

In addition to that, the error message helps, as well (if you got any).

From what I can see, you're trying to use the wrong function:
rs.testBundledcable does not exist; you have to use rs.testBundledInput.
mayaman79 #3
Posted 07 March 2012 - 05:04 PM
Sorry, it was a typo on my part, it was rs.testbundledInput

And it gives me no errors, sorry about that, ill update my first post now.
mayaman79 #4
Posted 07 March 2012 - 10:46 PM
I think i maybe know my own "problem" at the moment.


The code:



event = os.pullEvent()



Do that make the program wait for a event to happend before it goes next line?
Espen #5
Posted 08 March 2012 - 05:28 AM
I think i maybe know my own "problem" at the moment. The code:
 event = os.pullEvent() 
Do that make the program wait for a event to happend before it goes next line?
Yes, it basically calls coroutine.yield(), wich passes control back to the program that started the coroutine in which your program is running.
Ultimately it's a chain of yields that goes back all the way to ComputerCraft itself, which then checks all the possible events that can happen, like redstone, timers, keyboard inputs etc.
And if any one of these has occurred, they will be returned as parameters to coroutine.resume() until it finally comes back to the coroutine in which your program is running and where you have used os.pullEvent().

tl;dr
Yes, that's exactly what happens. :mellow:/>/>