Posted 11 March 2012 - 05:27 PM
Hey,
I am not sure if it is "enough" for a tutorial, but I would like to try ^^
I used the new peripheral API which came in 1.3 to detect if there is a modem and on which side it is.
Of course you could ask for any peripheral.
As you can see, it is really simple.
So I think this tutorial/snippet is mostly usefull for beginners.
I am not sure if it is "enough" for a tutorial, but I would like to try ^^
I used the new peripheral API which came in 1.3 to detect if there is a modem and on which side it is.
Of course you could ask for any peripheral.
Spoiler
function hasPeripheral(name)
local Sides = {"back","right","left","front","top","bottom"} -- a simple list of all sides
int = 1 -- An integer for going trough the list index
repeat
if peripheral.isPresent(Sides[i]) then -- checks if there is an peripheral at the current side
if peripheral.getType(Sides[i]) == name then -- when yes, then check if it is the right peripheral
side = Sides[i]
end
end
int = int + 1
until int == #Sides or sides ~= nil -- stop going trough the list index if every index was checked or the searched peripheral was found.
return side -- gives back the side on that the peripheral is placed. If the computer/turtle hasn't got the peripheral it will return nil.
end
As you can see, it is really simple.
So I think this tutorial/snippet is mostly usefull for beginners.