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

[SOLVED][CC1.5][SMP 1.4.7] rednet.isOpen returns false, not nil?

Started by Rihlsul, 25 March 2013 - 04:46 PM
Rihlsul #1
Posted 25 March 2013 - 05:46 PM
So, according to the wiki (http://computercraft...iki/Rednet_(API)):

rednet.isOpen "Returns true if the wireless modem is open or nil if not."

I've been running into issues where I check for nil and it's coming back false. Is that a bug or outdated wiki? I didn't want to just change it. If it does now return false if it's not open, is there a nil result (such as "there is no modem")?
Alekso56 #2
Posted 26 March 2013 - 12:19 PM
Please Note
As of ComputerCraft 1.5, the Rednet API is just a wrapper for modems and channels.
Rihlsul #3
Posted 26 March 2013 - 03:59 PM
A hot air balloonist was flying across the country when his balloon developed a leak. He landed in a field near a road and asked a motorist: “Where am I?” The motorist answered: “You’re in a hot air balloon and you just landed in a farmer’s field.” The balloonist replied: “You must be a consultant. You just told me something that is perfectly obvious, totally accurate, and of absolutely no use.”

Yep, it is just a wrapper. That's fine, and I'm looking forward to Channels. However, the documentation for isOpen for 1.5 does not clarify the returns either. So, code I wrote in 1.4.7 is broken in 1.5. The Wiki download info about changes says specifically "The rednet API still functions as before." but does not – if you believe the wiki for rednet.

As I said, I'd be fine with changing the Wiki to give useful info, but I do not know how the isOpen function is meant to behave. I *like* the new function, I'd rather it return true/false (true/false/nil?) than true/nil - but CC is closed source, so I can't poke about to make the results right except through black-boxing some different scenarios.

I'm a consultant so the opening joke is meant to be in good spirits. :D/>
theoriginalbit #4
Posted 26 March 2013 - 04:03 PM
why can't you just fix your code so that nil is used as logical false. like it is in Lua anyways! i.e.

-- instead of doing this
if rednet.isOpen('right') == true then

-- just do
if rednet.isOpen('right') then

and then just use

if peripheral.getType('side') ~= 'modem' then
  print("You have not attached a modem")
end

EDIT: Also everytime I tried to use rednet.isOpen it never worked.
Edited on 26 March 2013 - 03:05 PM
Cloudy #5
Posted 26 March 2013 - 11:34 PM
Why do you just not look in the Lua code to see it clearly returns false? When rednet was rewritten, we accidentally ommitted that functionality.

Way to cover both would just be checking rednet.isOpen() directly - that way false OR nil will fail the check.
Rihlsul #6
Posted 27 March 2013 - 02:09 AM
Sounds good, I'll update my Lua to make more sense.

Updated the Modem API page so it shows up in the API list. I've adjusted the Rednet API page to have a better description for isOpen. Oddly, when I linked the [[rednet.isOpen]] function to a wiki page, one already existed with examples like y'all outlined (ie - don't compare for false/nil).

Thanks for the feedback, the wiki is now clearer.
Cloudy #7
Posted 27 March 2013 - 02:18 AM
Thanks for updating the wiki, also :D/>
Rihlsul #8
Posted 27 March 2013 - 02:22 AM
Sure thing. I'm still noob enough (hence not knowing a smarter Lua true check) that I didn't want to edit before asking. In retrospect, this thread should have been in Ask a Pro, not bugs. What's amusing is that I had to invent/code channels in my first project, not realizing what was coming in 1.5. :lol:/>