Hi there!
Just a quick question, is there a way to check if a modem exists and return the parameters true/false and the side which it is on? If not, is there something out there that could help me do this?
Thank you very much for your time!
0
5 replies to this topic
#1
Posted 09 January 2013 - 04:19 PM
#2
Posted 09 January 2013 - 04:23 PM
This should do the trick...
to use this you would do this
function findModem() for _, v in pairs( rs.getSides() ) do if peripheral.isPresent( v ) and peripheral.getType( v ) == "modem" then return true, v end end return false, nil end
to use this you would do this
local exist, side = findModem()
Edited by TheOriginalBIT, 09 January 2013 - 04:24 PM.
#3
Posted 09 January 2013 - 04:31 PM
Great! Thanks for the quick reply! So i would place the
<code>
local exist, side = findmodem()
</code>
and If i wanted to check it existed, i would go:
<code>
if exist == true then
--code
else
print("Please place a modem on the computer!")
end
</code>
and if i was to send a rednet message, I could go:
<code>
rednet.open(side)
rednet.broadcast("Whatevs")
rednet.close(side)
</code>
That would work right?
<code>
local exist, side = findmodem()
</code>
and If i wanted to check it existed, i would go:
<code>
if exist == true then
--code
else
print("Please place a modem on the computer!")
end
</code>
and if i was to send a rednet message, I could go:
<code>
rednet.open(side)
rednet.broadcast("Whatevs")
rednet.close(side)
</code>
That would work right?
#4
Posted 09 January 2013 - 04:34 PM
looks good
#5
Posted 09 January 2013 - 04:38 PM
ftank12, on 09 January 2013 - 04:31 PM, said:
That would work right?
yes that would work. alternatively you could just have it return the side or nil. then do this
if not side then -- nil in Lua is interpreted as false print( "No modem" ) end rednet.open( side ) -- ... etc
also an fyi these are the code tags ( you were close though )
[code] [/code]
#6
Posted 09 January 2013 - 04:39 PM
Just tried it out, works perfectly!
Thanks so much!!
Thanks so much!!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users