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

Help with rednet.open

Started by grand_mind1, 05 January 2014 - 12:42 AM
grand_mind1 #1
Posted 05 January 2014 - 01:42 AM
I'm trying to make a function in a program that will check if a turtle has a wireless modem. I thought this would be pretty simple but rednet.open is not acting the way I thought it would. This is what I have so far:

if rednet.open("right") then
    print("Rednet Open.")
else
    print("No Modem.")
end
I thought this would work so that if the turtle was able to open a modem on its right side then it would be true so it would print rednet open. However, it prints no modem but still opens the modem. I've got no idea as to why this is happening.
Help is appreciated!
Thanks! :D/>
Beatsleigher #2
Posted 05 January 2014 - 02:24 AM
Uhm. rednet.open("<Side>") only opens a rednet port on the specified side.
To check if a port is open, you'd use

rednet.isopen()
grand_mind1 #3
Posted 05 January 2014 - 02:32 AM
I don't think you understand my issue. I want to check if there is a modem present at all. Not just if there is a modem open.
Beatsleigher #4
Posted 05 January 2014 - 02:34 AM
I guess what you could try is using the peripheral API if you want to check if a modem is is present.
Or you could try to open a modem on a side and then use isOpen(). That'd then return true if the rednet port is open and false if not.
6677 #5
Posted 05 January 2014 - 06:00 AM
do not use rednet for that check, it returns nil, not true or false.

http://www.computerc...ipheral-basics/
This will help. You need to be using the peripheral API to detect the modem itself.


local sides = { "top", "bottom", "left", "right", "front", "back" }
print("Finding modems...")
for i = 1, #sides do
  if peripheral.isPresent(sides[i]) then
		if peripheral.getType(sides[i]) == "modem" then
		  print("Found: "..sides[i])
		end
  end
end
Modified from cod in the above link.
Edited on 05 January 2014 - 06:28 AM