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

Attaching a rednet modem during program runtime

Started by Adamski1997, 11 May 2017 - 12:21 PM
Adamski1997 #1
Posted 11 May 2017 - 02:21 PM
Hi,

I want to be able to attach a rednet moden during the runtime of a program and use it. However, when I try to do so I get the following error:


peripheral:9: No such method getNamesRemote

My code is below:


local printed1 = false
local printed2 = false

while true do
  
   if not pcall(rednet.open, "top") then
	  if not printed1 then
		 printed1 = true
		 term.clear()
		 term.setCursorPos(1, 1)
		 print("There is no modem attached to the top of this computer!")
	  end
   else
	  local serverID = rednet.lookup("protocol", "hostname")
	  if not serverID then
		
		 if not printed2 then
			printed2 = true
			term.clear()
			term.setCursorPos(1, 1)
			print("Unable to contact the server")
		 end
	  else
		  term.clear()
		  term.setCursorPos(1, 1)
		  print("Sucessfully connected")
		  break
	  end

   end

end
	

If I start the program with no modem attached, it prints correctly. If I afterwards attach a modem without ending the program, it gives the error mentioned above.

If I start the program with the modem attached already it all works fine and prints sucessfully connected.

Is there any way around this or do I have to restart the program after the modem is connected?
Edited on 11 May 2017 - 12:23 PM
Adamski1997 #2
Posted 11 May 2017 - 03:38 PM
I managed to fix it myself by using os.pullEvent("modem") to wait between iterations of the loop