WIFI modem detector - finds and opens modem
BigSHinyToys 29 Mar 2012
This code will open find a modem and open it.
add the full code to the top of your program and it will work or just use the function it is up to you.
line three can be substituted with
local listOfSides = { "top" , "bottom" , "front" , "left" , "right" , "back" }
but not recommended
add the full code to the top of your program and it will work or just use the function it is up to you.
line three can be substituted with
local listOfSides = { "top" , "bottom" , "front" , "left" , "right" , "back" }
but not recommended
Spoiler
the section bellow this line (modemOn = openRednet()) shows a possible way to use this function.
Wolvan 29 Mar 2012
Made something like that in my rna API. Mind if I put in your code instead of mine?
Does this open bundled cable rednet too?
Does this open bundled cable rednet too?
BigSHinyToys 29 Mar 2012
it only works for wifi not cable
edit if it is useful to you please use it no need to credit me either
edit if it is useful to you please use it no need to credit me either
immibis 29 Mar 2012
Really?
Also you missed "back".
Also you missed "back".
-- Untested code local function openRednet() for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then rednet.open(side) return side end end print("no wifi present") end modemSide = openRednet() if modemSide == nil then print("No modem connected") else print("Opened modem on "..modemSide) end
Espen 29 Mar 2012
@immibis
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do... it might be better to use this instead:
for _,side in ipairs(rs.getSides()) do
BigSHinyToys 29 Mar 2012
immibis, on 29 March 2012 - 10:47 AM, said:
Really?
Also you missed "back".
-- snipped code --
Also you missed "back".
-- snipped code --
I had seen a lot of programs that say place WI FI modem on "left" or it wont work and already having written this thought it would be useful. So if you would like to post your code in your own topic GO ahead or else don't knock a noob that tried to help.
thank you for finding that problem. I have corrected it by adding "back"
Espen, on 29 March 2012 - 11:28 AM, said:
@immibis
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do... it might be better to use this instead:
for _,side in ipairs(rs.getSides()) do
works.
Wolvan 29 Mar 2012
BigSHinyToys, on 29 March 2012 - 12:58 PM, said:
Espen, on 29 March 2012 - 11:28 AM, said:
@immibis
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
Come on, be nice. />
Not everyone is on the same level.
On another note:
since one can never be sure if internal names might change between CC versions, it might be better to iterate over all sides using rs.getSides().
E.g. instead of ...
for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do... it might be better to use this instead:
for _,side in ipairs(rs.getSides()) do
works.
BigSHinyToys 29 Mar 2012
Wolvan, on 29 March 2012 - 02:04 PM, said:
added and credited
I got curious and tried rs.getSides() it is exactly what my table line does.so it can be swaped out if you want.
I was looking for information on rs.getSides() in help is it there and I'm just not finding it or is it a undocumented function??
Espen 29 Mar 2012
@BigSHinyToys:
Yes, it returns all the valid redstone sides. So even if Dan would change the names of them, as long as he doesn't change the function name of getSides() it will always return all the sides without you having to fix your programs in the future. Also it's shorter to write, so all in all it's more "future-safe" and more compact.
It doesn't seem to be documented in the help page of "rs" though, but only in the one of "redstone", which is quite odd, because they are eqivalent and "rs" is just kind of an alias of "redstone". Also it doesn't explicitly say what getSides() does, but the name should give it away in this case. />
Yes, it returns all the valid redstone sides. So even if Dan would change the names of them, as long as he doesn't change the function name of getSides() it will always return all the sides without you having to fix your programs in the future. Also it's shorter to write, so all in all it's more "future-safe" and more compact.
It doesn't seem to be documented in the help page of "rs" though, but only in the one of "redstone", which is quite odd, because they are eqivalent and "rs" is just kind of an alias of "redstone". Also it doesn't explicitly say what getSides() does, but the name should give it away in this case. />
Wolvan 29 Mar 2012
BigSHinyToys, on 29 March 2012 - 02:57 PM, said:
Wolvan, on 29 March 2012 - 02:04 PM, said:
added and credited
I got curious and tried rs.getSides() it is exactly what my table line does.so it can be swaped out if you want.
I was looking for information on rs.getSides() in help is it there and I'm just not finding it or is it a undocumented function??
BigSHinyToys 29 Mar 2012
Wolvan, on 29 March 2012 - 05:24 PM, said:
Yeah I already swapped rs.getSides() with your table. Does my API work? Didn't have time to test
local listOfSides = { rs.getSides() }
it should be
local listOfSides = rs.getSides()
this is because rs.getSide{} returns a table all we need to do is make a variable equal to it
example
table1 = {"a","b","c"}
table2 = table1
print(table2[1])
print(table2[2])
print(table2[3])
---- will return ----
a
b
c
Espen 29 Mar 2012
But why waste a variable by assigning it to rs.getSides()?
I mean, as long as you don't want to make changes to the table holding the sides, but only ever want to read the sides from it, then you don't really need this...
You can just as well use it directly then, like this...
Not telling how to do it, just trying to help keep the code smaller. So no offense, m'kay? />
I mean, as long as you don't want to make changes to the table holding the sides, but only ever want to read the sides from it, then you don't really need this...
local listOfSides = rs.getSides() for key, value in pairs( listOfSides ) do -- Do something end
You can just as well use it directly then, like this...
for key, value in pairs( rs.getSides() ) do -- Do something end
Not telling how to do it, just trying to help keep the code smaller. So no offense, m'kay? />
Wolvan 29 Mar 2012
BigSHinyToys, on 29 March 2012 - 06:30 PM, said:
Wolvan, on 29 March 2012 - 05:24 PM, said:
Yeah I already swapped rs.getSides() with your table. Does my API work? Didn't have time to test
local listOfSides = { rs.getSides() }
it should be
local listOfSides = rs.getSides()
this is because rs.getSide{} returns a table all we need to do is make a variable equal to it
example
table1 = {"a","b","c"}
table2 = table1
print(table2[1])
print(table2[2])
print(table2[3])
---- will return ----
a
b
c
Cloudy 30 Mar 2012
I really applaud your effort. However the code below is much more efficient and should probably be used instead. I'd take note of how iteration through a table is performed.
immibis, on 29 March 2012 - 10:47 AM, said:
Really?
Also you missed "back".
Also you missed "back".
-- Untested code local function openRednet() for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then rednet.open(side) return side end end print("no wifi present") end modemSide = openRednet() if modemSide == nil then print("No modem connected") else print("Opened modem on "..modemSide) end