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.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Make rednet functions throw an error if rednet isn't open.
Started by Kingdaro, 03 October 2012 - 10:05 PMPosted 04 October 2012 - 12:05 AM
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.
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.
Posted 04 October 2012 - 12:20 AM
Nah, just try to remember the rednet…..
Posted 04 October 2012 - 12:23 AM
Haha, you think I didn't already try that?Nah, just try to remember the rednet…..
Posted 04 October 2012 - 12:33 AM
Sticky notes, brah….best way to remember ANYTHING.
Posted 04 October 2012 - 12:48 AM
Is there a sticky note mod for minecraft? :U
Posted 04 October 2012 - 12:54 AM
The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
Posted 04 October 2012 - 01:04 AM
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. :(/>/>The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
Posted 04 October 2012 - 01:20 AM
Wouldn't rednet.send() or rednet.broadcast() return false if called without rednet open?The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
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.
Posted 04 October 2012 - 02:48 AM
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".The difficulty with this is rednet also works on bundled cables - and no easy way to detect them.
Throwing the error could break existing programs though.
Posted 04 October 2012 - 02: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.
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.
Posted 04 October 2012 - 02:55 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.
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…
Posted 04 October 2012 - 04: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.
Posted 04 October 2012 - 12:25 PM
Agree. I also did that once and was struggling for 30 minutes to figure out that I just forgot to open the modem.
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?
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?
Posted 04 October 2012 - 03:21 PM
Rednet.send returns a sucess boolean.
Posted 04 October 2012 - 04:32 PM
So you got result_success=false but want your program to be stopped?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?
Use some assertion wrapping for yourself. No need to demand it for all.
Posted 04 October 2012 - 10: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.
And I just pressed control thinking I was typing in minecraft. >.<
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. >.<
Posted 04 October 2012 - 10:47 PM
That's alright. I have been pressing t in IRC lately to bring up the chat console… >.<And I just pressed control thinking I was typing in minecraft. >.<
Posted 04 October 2012 - 11:50 PM
I've already addressed this, and I will explain in further detail below.Rednet.send returns a sucess boolean.
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.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.
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.
Posted 04 October 2012 - 11: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?
Posted 05 October 2012 - 12:01 AM
If there really are that many programs that send rednet signals without opening their modem first, I suppose it makes sense.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?
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?
Posted 05 October 2012 - 12:13 AM
Or you could check for error conditions in your own code like a responsible programmer.
Posted 05 October 2012 - 12:15 AM
Or you could put this in your startup:
Since it loads automatically you can't forget it.
local send = rednet.send
rednet.send = function(...) return assert(send(...), "No modem open.") end
Since it loads automatically you can't forget it.
Posted 05 October 2012 - 12:19 AM
And then I have to reference this because it seems that you've skipped over it:
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.
I was going to do this anyway though.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.
Posted 05 October 2012 - 12:42 AM
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.
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.
Posted 05 October 2012 - 01:10 AM
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.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.
I don't really feel like repeating myself though, so just lock it or something.
Posted 05 October 2012 - 01: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.
Posted 05 October 2012 - 01: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
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
Posted 05 October 2012 - 01: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.
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.
Posted 05 October 2012 - 07: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.