←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

Find API

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

roger109z's Photo roger109z 05 Apr 2016

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.
Quote

Anavrins's Photo Anavrins 05 Apr 2016

So, is this the same as peripheral.find?
Quote

roger109z's Photo roger109z 06 Apr 2016

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

Anavrins's Photo Anavrins 06 Apr 2016

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.
Quote

roger109z's Photo roger109z 11 Apr 2016

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

Anavrins's Photo Anavrins 11 Apr 2016

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

Bomb Bloke's Photo Bomb Bloke 11 Apr 2016

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().
Quote

Dahknee's Photo Dahknee 28 May 2016

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