Jump to content




Make rednet functions throw an error if rednet isn't open.


  • This topic is locked This topic is locked
28 replies to this topic

#1 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 October 2012 - 11:05 PM

I'm not sure if it's just me because I'm stupid, but when I make rednet-based programs, I almost always forget to place a modem on the computers and to open them. I'm sitting here for half an hour trying to figure out why nothing is happening and I don't fix it right away because I'm not given an error.

Errors are annoying, but at the same time, they're probably one of the best things in programming. They tell you exactly where and how you've screwed up. It would be monumentally helpful if the computers simply stopped the program and told you to open rednet, instead of doing nothing. It's like someone screaming at you constantly, without telling you why.

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 03 October 2012 - 11:20 PM

Nah, just try to remember the rednet.....

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 October 2012 - 11:23 PM

View PostCranium, on 03 October 2012 - 11:20 PM, said:

Nah, just try to remember the rednet.....
Haha, you think I didn't already try that?

#4 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 03 October 2012 - 11:33 PM

Sticky notes, brah....best way to remember ANYTHING.

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 October 2012 - 11:48 PM

Is there a sticky note mod for minecraft? :U

#6 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 03 October 2012 - 11:54 PM

The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 October 2012 - 12:04 AM

View PostCloudy, on 03 October 2012 - 11:54 PM, said:

The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
It would be awesome if they could though... But no, there is no sticky note mod...as far as I know, anyway... They are in what we call "The real world" in a fanciful place called "Outside". It's all the rage these days. :(/>

#8 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 October 2012 - 12:20 AM

View PostCloudy, on 03 October 2012 - 11:54 PM, said:

The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
Wouldn't rednet.send() or rednet.broadcast() return false if called without rednet open?

So instead of returning false, would it be possible to instead simply give an error?

In fact I could do some edits and make it so that it errors myself, just by storing the function as a local function and redefining the global one to error if the result of the stored local function is false.

#9 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 04 October 2012 - 01:48 AM

View PostCloudy, on 03 October 2012 - 11:54 PM, said:

The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
You still have to open the bundled cables. "Throw an error if no sides are open" is much easier than "throw an error if no modems or cables are connected".
Throwing the error could break existing programs though.

#10 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 October 2012 - 01:51 AM

The programs shouldn't try to send rednet signals without an open modem anyway. Programs would do the same in real life, right? If there's no internet connection available?

I know you're not going for realism here, but that's just something I'd imagine a program would do - throw an error if there's no medium through which to send rednet signals.

#11 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 04 October 2012 - 01:55 AM

View PostKingdaro, on 04 October 2012 - 01:51 AM, said:

The programs shouldn't try to send rednet signals without an open modem anyway. Programs would do the same in real life, right? If there's no internet connection available?

I know you're not going for realism here, but that's just something I'd imagine a program would do - throw an error if there's no medium through which to send rednet signals.

Actually, depending on the scenario, lots of communication systems send data regardless of connected media. They do throw an error though, when no data is coming back. (This is implemented in multiple layers of the ISO OSI model). You could go for that approach...

#12 ElvishJerricco

  • Members
  • 803 posts

Posted 04 October 2012 - 03:13 AM

It'd be crappy practice for it to throw an error. Making it crash because the network is unavailable? That's silly. Network is never a reliable thing. If Chrome crashed every time i wasn't connected to wifi i'd be pretty annoyed. The fact that send and broadcast return false when there's no rednet is perfect.

#13 matejdro

  • Members
  • 324 posts

Posted 04 October 2012 - 11:25 AM

Agree. I also did that once and was struggling for 30 minutes to figure out that I just forgot to open the modem.

View PostElvishJerricco, on 04 October 2012 - 03:13 AM, said:

It'd be crappy practice for it to throw an error. Making it crash because the network is unavailable? That's silly. Network is never a reliable thing. If Chrome crashed every time i wasn't connected to wifi i'd be pretty annoyed. The fact that send and broadcast return false when there's no rednet is perfect.

This is not really good comparison.

1. Chrome would throw an error if there is no network
2. Rednet IS reliable, there is always a network. Why would rednet opening/closing be unreliable?

#14 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 04 October 2012 - 02:21 PM

Rednet.send returns a sucess boolean.

#15 Sebra

  • Members
  • 726 posts

Posted 04 October 2012 - 03:32 PM

View PostKingdaro, on 04 October 2012 - 12:20 AM, said:

Wouldn't rednet.send() or rednet.broadcast() return false if called without rednet open?
So instead of returning false, would it be possible to instead simply give an error?
So you got result_success=false but want your program to be stopped?
Use some assertion wrapping for yourself. No need to demand it for all.

#16 OmegaVest

  • Members
  • 436 posts

Posted 04 October 2012 - 09:41 PM

Sebra for the win. So I pile on top with some noobish ranting.

If you aren't familiar with it, there is an error command in the APIs somewhere. Using that, I have prepared a noob code fragment for you.

if not rednet.send(id, msg) then
   if rednet.isOpen() then
      print("ID or message Invaild")
   else
      error("No network detected")
   end
else
   print("Message Sent, awaiting response.")
end





And I just pressed control thinking I was typing in minecraft. >.<

#17 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 04 October 2012 - 09:47 PM

View PostOmegaVest, on 04 October 2012 - 09:41 PM, said:

And I just pressed control thinking I was typing in minecraft. >.<
That's alright. I have been pressing t in IRC lately to bring up the chat console... >.<

#18 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 October 2012 - 10:50 PM

View Postardera, on 04 October 2012 - 02:21 PM, said:

Rednet.send returns a sucess boolean.
I've already addressed this, and I will explain in further detail below.


View PostSebra, on 04 October 2012 - 03:32 PM, said:

So you got result_success=false but want your program to be stopped?
Use some assertion wrapping for yourself. No need to demand it for all.
This doesn't even relate to the reason why I ask for this. When I make a program, all I type is "rednet.send 'blahblahblah'" and it takes me a while to figure out why nothing's happening because I'm not told that I'm doing something wrong - like basically every other mistake in programming, syntax errors and nil calls for example. It's the same as typing something without parentheses and the program still (somehow) continues on it's merry way.

By the time I've already written checks to see if the modem is there, I can already see if it's there because I have eyes, so there would be no point in doing so.

Also, I'm not "demanding", I'm making a request, but with stronger wording. I've proved in a tumblr post that periods make sentences more serious than if they were without periods, sorry for the misconception.

#19 Fatal_Exception

  • New Members
  • 105 posts

Posted 04 October 2012 - 10:58 PM

So you want an API to throw a fatal error, breaking many existing programs, instead of failing gracefully, because you don't want to change your habits?

#20 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 October 2012 - 11:01 PM

View PostFatal_Exception, on 04 October 2012 - 10:58 PM, said:

So you want an API to throw a fatal error, breaking many existing programs, instead of failing gracefully, because you don't want to change your habits?
If there really are that many programs that send rednet signals without opening their modem first, I suppose it makes sense.

Otherwise there shouldn't be a problem.

Or perhaps, if you, for some reason, wanted to send rednet signals without the modem open, you could just pass an argument like 1 to the function to prevent it from erroring?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users