Jump to content




Random Rednet Too Long Without Yeilding


  • You cannot reply to this topic
2 replies to this topic

#1 applesauce10189

  • Members
  • 162 posts

Posted 06 May 2014 - 10:21 PM

I have a single player world in which I code things for the sake of coding and improving a computercraft facility I've made. Of all the times I've had this world open/close one time out of all the cumputers/programs I have this one randomly got a too long without yeilding from rednet. Not quite sure how to fix so here's my code:

rednet.open("left")
local lights = false
while true do
local id, message = rednet.receive()
  if message == "glcheck" then
	rednet.broadcast("glgood")
  end
  if id == 4 then
	if message == "l1" then
	  lights = true
	elseif message == "l2" then
	  lights = false
	end
  end
  if lights then
	rs.setOutput("right", true)
  elseif not lights then
	rs.setOutput("right", false)
  end
end

EDIT: Hmm. Just noticed that with the font code uses L and 1 look the exact same.

Edited by applesauce10189, 06 May 2014 - 10:24 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 May 2014 - 10:43 PM

That code shouldn't have that problem. What version of CC are we talking about?

Given that you're saying it's only happened once, it might be worth mentioning that sometimes rednet messages sent to a given system won't be received for no good reason. It doesn't really seem to matter here, but in cases where a script absolutely hinges on messages getting through, you might consider making use of timeouts to resend messages if the correct replies don't come back.

The only real improvement I can see would be to turn this sort of thing:

  if lights then
        rs.setOutput("right", true)
  elseif not lights then
        rs.setOutput("right", false)
  end

... into this:

  rs.setOutput("right", lights)

Edit: Well I suppose you could do away with "lights" altogether.

  if message == "l1" or message == "l2" then rs.setOutput("right", message == "l1") end

Edited by Bomb Bloke, 06 May 2014 - 10:48 PM.


#3 applesauce10189

  • Members
  • 162 posts

Posted 09 May 2014 - 08:33 AM

View PostBomb Bloke, on 06 May 2014 - 10:43 PM, said:

That code shouldn't have that problem. What version of CC are we talking about?
1.61

View PostBomb Bloke, on 06 May 2014 - 10:43 PM, said:

but in cases where a script absolutely hinges on messages getting through, you might consider making use of timeouts to resend messages if the correct replies don't come back.
Actually I already do use timeouts, you see, the only reason I actually noticed the program bugged out was because I have one central computer that sends out checks and will wait a few seconds and if it doesn't get a certain reply it prints on a monitor that that program is offline.

View PostBomb Bloke, on 06 May 2014 - 10:43 PM, said:

The only real improvement I can see would be to turn this sort of thing:
[/color][color=#000088]if[/color][color=#000000] lights [/color][color=#000088]then[/color]
[color=#000000]		rs[/color][color=#666600].[/color][color=#000000]setOutput[/color][color=#666600]([/color][color=#008800]"right"[/color][color=#666600],[/color][color=#000000] [/color][color=#000088]true[/color][color=#666600])[/color]
[color=#000000]  elseif [/color][color=#000088]not[/color][color=#000000] lights [/color][color=#000088]then[/color]
[color=#000000]		rs[/color][color=#666600].[/color][color=#000000]setOutput[/color][color=#666600]([/color][color=#008800]"right"[/color][color=#666600],[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600])[/color]
[color=#000000]  [/color][color=#000088]end


... into this:

rs[/color][color=#666600].[/color][color=#000000]setOutput[/color][color=#666600]([/color][color=#008800]"right"[/color][color=#666600],[/color][color=#000000] lights[/color][color=#666600])

Oh well, thanks for the help though! By the way, sorry for the 3 day late reply xD various things distracted me.

EDIT: Jesus christ. Something about the way I did this just flat out doesn't like me...

Edited by applesauce10189, 09 May 2014 - 08:34 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users