Hiranus icon

Peripheral Search

Hiranus | PRO | 05/02/14 04:46:15 PM UTC | 0 ⭐ | 361 👁️ | Never ⏰ | []
Lua |

1.26 KB

|

None

|

0 👍

/

0 👎

function search(perToFind)
    local printMode = false
    if perToFind == "print" or perToFind==nil then
            printMode=true
    end
    if printMode == true then
        term.clear()
        term.setCursorPos(1,1)
    end
    local perip = peripheral.getNames()
        for i=1, #perip do      
            if printMode == true then
                    if peripheral.getType(perip[i])=="modem" then
                        if peripheral.call(perip[i],"isWireless") then
                            print(perip[i] .. " -- modem.wireless")
                        else
                            print(perip[i] .. " -- " ..peripheral.getType(perip[i]))
                        end
                    else
                        print(perip[i] .. " -- " ..peripheral.getType(perip[i]))
                    end
            else
                if perToFind=="modem" or perToFind=="modem.wireless" then
                    if peripheral.getType(perip[i])=="modem" then
                        if peripheral.call(perip[i],"isWireless") and perToFind=="modem.wireless" then
                            return perip[i]
                        elseif not peripheral.call(perip[i],"isWireless") and perToFind=="modem" then
                            return perip[i]
                        end
                    end
                else
                    if perToFind==peripheral.getType(perip[i]) or perToFind==perip[i] then
                        return perip[i]
                    end
                end
            end
        end
    if printMode == false then
        throw("No such peripheral: " ..perToFind)
    end
end
 
function wsearch (perToFind)
    return peripheral.wrap(search(perToFind))
end

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎