Posted 15 September 2014 - 09:05 AM
hi all again, today I bring you a program I had to do to see if I have activated the RedNet on a computer or a turtle, the program is very simple:
1 Disable any active RedNet on computer / turtle
2nd Search all sides if there is a modem connected and active RedNet
3rd If RedNet is active on one side, and there is no an attached modem, which informs you and tells you that you add one position *
4th If there is no modem connected, and RedNet not find an active connection, you reported, you add a modem *
* You must restart the program to do the check and activate both RedNet as the modem :)/>
here is the code
http://pastebin.com/0k5RvWke
be free to tell me if you find any bug, mistake or anything, and again, sorry for my bad english Q_Q
1 Disable any active RedNet on computer / turtle
2nd Search all sides if there is a modem connected and active RedNet
3rd If RedNet is active on one side, and there is no an attached modem, which informs you and tells you that you add one position *
4th If there is no modem connected, and RedNet not find an active connection, you reported, you add a modem *
* You must restart the program to do the check and activate both RedNet as the modem :)/>
here is the code
http://pastebin.com/0k5RvWke
Spoiler
-- FUNCIONAMIENTO / OPERATION
-- Spanish
--------------------------------------------------------------------------------
-- 1º Si hay presente un moden, activa la rednet en el 1º lado que lo encuentre
-- 2º si no hay un modem, pero esta activa la rednet, lo desactiva
-- 3º Si no hay un modem, sale del programa
--------------------------------------------------------------------------------
-- English
--------------------------------------------------------------------------------
-- 1º If present a moden, active it in the 1st RedNet side who finds
-- 2º if no modem, but is RedNet activated, it disabled
-- 3º If no modem, exit the program
--------------------------------------------------------------------------------
-- Limpia la pantalla
-- clean the screen
function Limpiar()
term.clear()
term.setCursorPos(1,1)
end
-- Escribe el texto letra a letra
-- Write the text letter by letter
sp2 = textutils.slowPrint
-- Desactiva la conexion RedNet activa
-- Disables the connection active RedNet
function DesactivarRedNet()
for side, label in ipairs(rs.getSides()) do
rednet.close(label)
end
end
-- English / Spanish translate
local translate = {["top"] = "Arriba", ["bottom"] = "Abajo", ["left"] = "Izquierda", ["right"] = "Derecha", ["front"] = "Delante", ["back"] = "Detras"}
-- Funcion para conectar RedNet
-- Function to connect RedNet
function ConetarRedNet()
local lado
for side, label in ipairs(rs.getSides()) do
lado = translate[label]
Limpiar()
print("looking modem")
-- print("Buscando modem")
term.setCursorPos(15,1)
sp2(".............")
if peripheral.isPresent(label) then
if peripheral.getType(label) == "modem" then
DesactivarRedNet()
rednet.open(label)
Limpiar()
print("Modem enabled: ", lado)
-- print("Modem activado: ", lado)
sp2("Closing program ....")
-- sp2("Cerrando programa....")
sleep(2)
Limpiar()
return(true)
end
end
if not peripheral.isPresent(label) then
if rednet.isOpen(label) == true then
DesactivarRedNet()
Limpiar()
print("Active RedNet on: "..lado..", but is not a modem added in that position, add one")
-- print("RedNet activo en: "..lado..", pero no se encuentra añadido un modem en esa posición, añada uno.")
sleep(3)
sp2("Closing connection RedNet....")
-- sp2("Cerrando conexión a RedNet....")
sleep(3)
Limpiar()
return(true)
end
end
end
sp2("No modem, no connection, add one to the device")
--sp2("No hay modem, imposible conexion, añada uno al dispositivo")
sleep(4)
Limpiar()
return(false)
end
ConetarRedNet()
be free to tell me if you find any bug, mistake or anything, and again, sorry for my bad english Q_Q
Edited on 15 September 2014 - 05:24 PM