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

#21 Fatal_Exception

  • New Members
  • 105 posts

Posted 04 October 2012 - 11:13 PM

Or you could check for error conditions in your own code like a responsible programmer.

#22 faubiguy

  • Members
  • 213 posts

Posted 04 October 2012 - 11:15 PM

Or you could put this in your startup:
local send = rednet.send
rednet.send = function(...) return assert(send(...), "No modem open.") end

Since it loads automatically you can't forget it.

#23 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 October 2012 - 11:19 PM

And then I have to reference this because it seems that you've skipped over it:

View PostKingdaro, on 04 October 2012 - 10:50 PM, said:

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.


View Postfaubiguy, on 04 October 2012 - 11:15 PM, said:

Or you could put this in your startup:
local send = rednet.send
rednet.send = function(...) return assert(send(...), "No modem open.") end

Since it loads automatically you can't forget it.
I was going to do this anyway though.

#24 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 04 October 2012 - 11:42 PM

To be honest, it returns false. Would it be so hard for you to just check if it succeeded? Heck even assert would throw an error for you.

assert(rednet.send(), "Could not send. Please check port open")

Also even if you type rednet.send() in the lua prompt it will show a false return value.

#25 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 05 October 2012 - 12:10 AM

View PostCloudy, on 04 October 2012 - 11:42 PM, said:

To be honest, it returns false. Would it be so hard for you to just check if it succeeded? Heck even assert would throw an error for you.

assert(rednet.send(), "Could not send. Please check port open")

Also even if you type rednet.send() in the lua prompt it will show a false return value.
As I've already said before, by the time I've already made the check I will have remembered to throw the modem on and open rednet.

I don't really feel like repeating myself though, so just lock it or something.

#26 Fatal_Exception

  • New Members
  • 105 posts

Posted 05 October 2012 - 12:12 AM

If you make it a habit to always check return values when things can fail, you won't be surprised when they do. See: responsibility.

#27 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 05 October 2012 - 12:14 AM

your repeating the same things over and over, just make your own function to open it and error if its not on, and even open the first available modem instead of specifying one

i dont get it? how do you forget to use rednet.open(),
and when you do that you sould automatically check if its on the right side

#28 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 05 October 2012 - 12:46 AM

Why not just ask for the modems to come connected to the computers and auto enable?? lol J/K J/K!!!!

This is really just a personal issue, you need to figure out how to remember to turn them on. The mod can't do everything for you, there just wouldn't be any fun in that.

I forget it from time to time, but thats my fault. I've made my own little function that I put in all programs to check for it and yell at me if I forget. Its part of the standard set of functions that I put in all of my scripts.

#29 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 05 October 2012 - 06:56 AM

Since I don't see the point in this - we already do something when failed - I'm closing this topic. I do understand your point, but we can't error for every single thing.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users