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

Setting Redstone Output to False causes Rednet to send again

Started by Maccyjam, 21 January 2013 - 06:10 AM
Maccyjam #1
Posted 21 January 2013 - 07:10 AM
Hey,
I've got a little program that I wrote that uses a MiscPeripherals player detector to check whether I was the one who used the detector and if so, activate some redstone. Also, regardless of who used the detector, it sends a log with the player's name to a listener program on a different computer.
However, the issue i've been experiencing is is that when setting the redstone on, waiting 3 seconds then turning it off, the 'client' computer sends another log with data 'nil' to the listener computer when the redstone is turned off. After taking away the redstone code, I can see that it is the redstone that is causing the problem.
Here's the code:

-- Player Detecting Test
local outputSide = "back" -- Side to output redstone signal to.
local logServerID = 3 -- Logging Server ID. Can be found by running 'id'.
local redn = rednet.open("left")

function checkPlayer()
print("Welcome. Please provide identification.")
		local pla2, playerName23 = os.pullEvent(player)
		print(playerName23)
		rednet.send(logServerID,tostring(playerName23))
		if playerName23 == "maccyjam" then
  redstone.setOutput("back",true)	
				sleep(2)
  redstone.setOutput("back",false)	
end
checkPlayer()
end

checkPlayer()

Any help would be greatly appreciated. Also, on a fairly unrelated note, if there are other events such as keypresses, it sends the ID of that key to the listener. Is there a way to only accept event data from the player detector?
Thanks,
SuicidalSTDz #2
Posted 21 January 2013 - 07:14 AM
Hey,
I've got a little program that I wrote that uses a MiscPeripherals player detector to check whether I was the one who used the detector and if so, activate some redstone. Also, regardless of who used the detector, it sends a log with the player's name to a listener program on a different computer.
However, the issue i've been experiencing is is that when setting the redstone on, waiting 3 seconds then turning it off, the 'client' computer sends another log with data 'nil' to the listener computer when the redstone is turned off. After taking away the redstone code, I can see that it is the redstone that is causing the problem.
Here's the code:

-- Player Detecting Test
local outputSide = "back" -- Side to output redstone signal to.
local logServerID = 3 -- Logging Server ID. Can be found by running 'id'.
local redn = rednet.open("left")

function checkPlayer()
print("Welcome. Please provide identification.")
		local pla2, playerName23 = os.pullEvent(player)
		print(playerName23)
		rednet.send(logServerID,tostring(playerName23))
		if playerName23 == "maccyjam" then
  redstone.setOutput("back",true)	
				sleep(2)
  redstone.setOutput("back",false)	
end
checkPlayer()
end

checkPlayer()

Any help would be greatly appreciated. Also, on a fairly unrelated note, if there are other events such as keypresses, it sends the ID of that key to the listener. Is there a way to only accept event data from the player detector?
Thanks,

This code is a bit messy, but from what I see you are telling your computer to do checkPlayer() twice? Or are you trying to loop the program? If you are then I would suggest using
while true do
checkPlayer()
end

EDIT: Please indent your code, it makes it easier for people to help you ;)/>
EDIT: The key events are due to you using the Player detector and how it prints the event and param

function checkPlayer()
print("Welcome. Please provide identification.")
				local pla2, playerName23 = os.pullEvent(player)
				print(playerName23)
				rednet.send(logServerID,tostring(playerName23))
				if playerName23 == "maccyjam" then
  redstone.setOutput("back",true)	  
								sleep(2)
  redstone.setOutput("back",false)	
end
checkPlayer()
end
checkPlayer()
Maccyjam #3
Posted 21 January 2013 - 07:44 AM
Thanks for the reply and sorry about the messy code, still getting used to it!
Taking out the first checkPlayer() and adding a loop around the other one causes it to have the same problem with it sending a 'nil' message to the listener. The idea was to loop the program but I can't find an appropriate way to do it without running into an issue such as this.
Thanks again.
remiX #4
Posted 21 January 2013 - 08:16 AM
player needs to be "player"?


while true do -- infinite loop
	print("Welcome. Please provide identification.")
	local pla2, playerName23 = os.pullEvent("player") -- player needs to be in " " unless you have a variable 'player'
	print(playerName23)
	rednet.send(logServerID,tostring(playerName23))
	if playerName23 == "maccyjam" then
		redstone.setOutput("back",true)         
		sleep(2)
		redstone.setOutput("back",false)      
	end
end

SuicidalSTDz #5
Posted 21 January 2013 - 08:33 AM
Thanks for the reply and sorry about the messy code, still getting used to it!
Taking out the first checkPlayer() and adding a loop around the other one causes it to have the same problem with it sending a 'nil' message to the listener. The idea was to loop the program but I can't find an appropriate way to do it without running into an issue such as this.
Thanks again.
No problem and good luck with Lua! :)/>
Maccyjam #6
Posted 21 January 2013 - 10:24 AM
player needs to be "player"?


while true do -- infinite loop
	print("Welcome. Please provide identification.")
	local pla2, playerName23 = os.pullEvent("player") -- player needs to be in " " unless you have a variable 'player'
	print(playerName23)
	rednet.send(logServerID,tostring(playerName23))
	if playerName23 == "maccyjam" then
		redstone.setOutput("back",true)		
		sleep(2)
		redstone.setOutput("back",false)	  
	end
end


This did the trick, solved both issues!
Thanks a lot! :D/>