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

Weird Rednet Bug

Started by McSick, 28 October 2013 - 07:40 AM
McSick #1
Posted 28 October 2013 - 08:40 AM
I have a computer craft program that has been working great for the longest time. Then all the sudden, it stopped working. Upon further investigation…The problem is the rednet.send() command. all the parameters seem to be right. In fact, it is sending the command as the turtle is doing what it should be on the command. However now all the sudden it closes the program on the computer instead of running the rest of the code. I have no clue why. Does anyone know more about the rednet.send command as to why it would close? Maybe a timeout issue?



I have a the portal program and the touchscreen program ran on startup.



Turtle Program: http://pastebin.com/eWyexecV
Computer Touchscreen: http://pastebin.com/Wqs1rArR
Button API: http://pastebin.com/rmjRHQ7X

I went ahead and commented in the ComputerTouchscreen program where things are closing. That rednet command is sent and the turtle runs its code.

What this is used for is a Mystcraft portal system in which the books are stored in a turtle and the turtle places the books. The monitor is a touch screen of pages to select which book to place.
kaioo1312 #2
Posted 28 October 2013 - 08:50 AM
What line?
TheOddByte #3
Posted 28 October 2013 - 09:00 AM
Are you getting any error code? If so then please post it otherwise it's hard for us to help you.
And which of those programs you posted above is actually erroring?
kaioo1312 #4
Posted 28 October 2013 - 09:09 AM
The only possible way that rednet.send() could time out is if there is no rednet modem or its not open
TheOddByte #5
Posted 28 October 2013 - 09:26 AM
Here's an function/code you can use to check if there are any modems open

--[[
	@description	"Checks all open modems"

	@return		 table
--]]
function checkOpenSides()

	local tOpenSides = {}
	for _,side in pairs(rs.getSides()) do
		if peripheral.getType(side) == "modem" then
			if rednet.isOpen(side) then
				table.insert(tOpenSides,side)
			end
		end
	end
  return tOpenSides
end

local sides = checkOpenSides()
if #sides == 0 then
	error("No modems open!", 0)
end

It will ofcourse error if you don't have any modems open.
theoriginalbit #6
Posted 28 October 2013 - 09:29 AM

if #sides = 0 then
	error("No modems open!", 0)
end

if #sides == 0 then
  error("No modems open!", 0)
end
TheOddByte #7
Posted 28 October 2013 - 10:35 AM

if #sides = 0 then
	error("No modems open!", 0)
end

if #sides == 0 then
  error("No modems open!", 0)
end
Wow.. I only indented by 4 and now when looking it's 8 D:
And thanks that you noticed that I forgot an '=' :)/>
McSick #8
Posted 28 October 2013 - 11:55 AM
I am not getting any errors and the modem is working. It sends the command to the turtle just fine. The turtle receives the command and runs it properly. As I said, it was working a few days ago. I can't really think of anything that changed that would cause it to stop working. If you look at


function sendTurtle(string, name)
  -- print("0")
  --  print(string)
  --  print(name)
  x =  rednet.send(turtleID, string) --CODE RUNS THIS
  --BUT CLOSES AND DOESNT RUN AFTER THIS
  -- print("1")
  button.flashButton(name, 5)
  -- print("2")

  setMain()
  -- print("3")

end

I have multiple prints to debug. It gets before the rednet.send command and prints all the stuff. None of the prints after print however. The command is sent and working, it just closes the program when its supposed to reset the screen back to the main screen. I have taken out the rednet.send command and the rest of the code runs which leads me to believe its the rednet command. I will look into the modem being open some more. I just don't see how it wouldn't be open since the commands are being sent.
McSick #9
Posted 28 October 2013 - 12:08 PM
To add on to what I just replied with, I added the following code


function sendTurtle(string, name)
  -- print("0")
  --  print(string)
  --  print(name)
  if(rednet.isOpen("left")) then
    print("in") -- it is printing this
   rednet.send(turtleID, string) --CODE RUNS THIS
    --BUT CLOSES AND DOESNT RUN AFTER THIS
    -- print("1")
    button.flashButton(name, 5)
    -- print("2")
end
  setMain()
  -- print("3")
end
which shows the modem is open.
sens #10
Posted 28 October 2013 - 12:25 PM
Change your variablename "string" to something else, what say? string is an API.
Bomb Bloke #11
Posted 28 October 2013 - 05:00 PM
I somewhat suspect that you're playing on a server, and the admin decided to make it a "happier place" by adding something like an error() line to that particular function in the default rom. That is to say, he thought CC rednet/modems to be bad for the server and tried to disable them (not too farfetched if running on older versions of CC, where they're indeed a very risky business when turtles are involved, though many admins seem to just be fixated on reducing "lag" via any means - realistic or otherwise).

Whether you're on a server or not, what versions of MineCraft/CC are you using, and are they part of a modpack? If so, which, and what version of that?

Just as a test I would write new scripts, something like:

rednet.open("left")

for i=1,10 do
  rednet.send(34, i)
  print(i)
end

rednet.close("left")

Since the Rednet API is pretty much just a wrapper for the modem API, I'd next try to bypass it and do the same thing a different way:

local modem = peripheral.wrap("left")

for i=1,10 do
  modem.transmit(34,os.getComputerID(),i)
  print(i)
end

(If the turtle is listening, it should see these messages as being the same as the rednet-sent messages.)

Do these also bug out? What if you run them on different computers?
McSick #12
Posted 28 October 2013 - 07:21 PM
Im the admin and I didn't turn off anything. I changed the code to use modem.transmit and like before, the command is sent, the turtle gets the command, and the computer turns off for some reason. So its not rednet based. Maybe just modem based. I'm using cc 1.53 for minecraft 1.5.2. Running ftb unleashed 1.1.4
Bomb Bloke #13
Posted 28 October 2013 - 07:30 PM
Earlier you said the program closed - now you're saying the computer turns off.

Can you still see the command line where you started each script from (does the program simply end), or does that get wiped off (the computer reboots)? Is there any odd delay when running those short scripts, or does it just finish up near-instantly?

Does anyone else have access to your world (admin or otherwise)?
McSick #14
Posted 29 October 2013 - 10:05 AM
Sorry I meant to say the program merely ended. The terminal is active and I can type in commands. It normally starts up the touchscreen program on boot then it should always stay in the program. It is supposed to be stuck in the while true loop. Somehow it is getting out of that loop via the sending information over the modem. It seems to finish up near-instantly.

As for access I do have people who play on it. Other admins are 2 of my friends and my girlfriend.
Bomb Bloke #15
Posted 29 October 2013 - 05:04 PM
Ok, so if those test scripts behave like that even on a new computer, and restarting the whole Minecraft server doesn't fix it, then that doesn't leave a lot of possibilities: Something in the server files has been messed up.

Assuming the server logs don't show some other mod-action popping up whenever you try to run your script, re-installing ComputerCraft is the next step. You may consider taking a copy of the current version the server has in case you're inclined to poke through it.