Jump to content




Find API

peripheral networking api

7 replies to this topic

Poll: Find API

Was this program useful to you?

You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Vote Guests cannot vote

#1 roger109z

  • Members
  • 53 posts
  • LocationCali beetch

Posted 05 April 2016 - 01:24 AM

This API is intended to find peripherals!

Pastebin code: wpA73N2E

Functions:

find.modem()
-finds any modem attached to your computer (returns the side string)

find.computer()
-finds any computer on the notwork or attacked to the computer (returns all computers table)


find.mon()
-finds any monitor connected to the network (returns all monitors table)

todo
-add filters for advanced monitors/computers
-add disks and printers
-add filters for checking if a modem is wireless

Edited by roger109z, 05 April 2016 - 01:28 AM.


#2 Anavrins

  • Members
  • 775 posts

Posted 05 April 2016 - 02:09 AM

So, is this the same as peripheral.find?

#3 roger109z

  • Members
  • 53 posts
  • LocationCali beetch

Posted 06 April 2016 - 02:35 AM

no peripheral.find wraps the first peripheral it finds this returns all of the peripherals and can be used for rednet.

#4 Anavrins

  • Members
  • 775 posts

Posted 06 April 2016 - 02:38 AM

peripheral.find does returns all peripherals...
With modem1, modem2, modem3 = peripheral.find("modem") or modems = { peripheral.find("modem") }
Additionally, it takes a filter function, peripheral.find("modem", function(side, obj) return obj.isWireless() end) to only get wireless modems, (return not obj.isWireless()) for only wired ones.
Similar thing with monitors using obj.isColor().

Edited by Anavrins, 06 April 2016 - 02:57 AM.


#5 roger109z

  • Members
  • 53 posts
  • LocationCali beetch

Posted 11 April 2016 - 03:12 AM

but peripheral.find WRAPS a modem
this returns the side so it can be used with rednet :P

#6 Anavrins

  • Members
  • 775 posts

Posted 11 April 2016 - 04:21 AM

peripheral.find("modem", function(side) rednet.open(side) end) would achieve the same thing.

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 April 2016 - 10:07 AM

Truth be told, peripheral.find("modem", rednet.open) would be more efficient again. Though I believe that one was pointed out to me in a similar fashion...

Suffice to say, while peripheral.find() is a great function with uses that aren't immediately obvious, this API may still be useful for a user who doesn't have it - there are a variety of CC builds in use out there, and 1.6 or later is required for peripheral.find().

#8 DannySMc

  • Members
  • 1,808 posts
  • Location/home/dannysmc95

Posted 28 May 2016 - 10:24 PM

I swear this is the code I gave you on slack... -__-





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users