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

[Question][Solved]How to get a string to output through redstone signal?

Started by Stormkrow, 01 June 2012 - 11:15 AM
Stormkrow #1
Posted 01 June 2012 - 01:15 PM
I wanna make it so that when the computer recieves a redstone signal at the 'back' side, it will output a message saying something like 'signal recieved'. How would i do this?
ardera #2
Posted 01 June 2012 - 01:50 PM
You can use os.pullEvent() :

while true do
  event, param = os.pullEvent()
  if event=="redstone" then
    if param=="back" then
	  print("signal recieved")
	  break
   end
  end
end
Stormkrow #3
Posted 01 June 2012 - 02:01 PM
Is there any other code that goes before that? i just tried it and connected signal to it and it does nothing?
my_hat_stinks #4
Posted 01 June 2012 - 03:42 PM
os.pullEvent doesn't return any parameters for the "redstone" event

You'll need something more along the lines of this:

local loop, HadPower = true, redstone.getInput("back")
while loop do
   local e = os.pullEvent("redstone")

   if e=="redstone" then --Just in case, should always be true
	 local power = redstone.getInput("back")
	
	 if power and not HadPower then
		--We got a pulse
	 elseif (not power) and HadPower then
		--We lost a pulse
	 end

      HadPower = power --Nearly forgot this bit :)/>/>
   end
end
Stormkrow #5
Posted 01 June 2012 - 03:52 PM
THANKS!