Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#########BRUM'S SLAVE COMPUTER ############
- -- System Variables
- local sides = {"left", "bottom", "top", "right", "back"}
- local myId = os.getComputerID()
- local version = 0.2
- local connected = false
- -- Find what side the modem is on and open the modem to the network
- function peripherals()
- for i = 1, 5 do
- if peripheral.getType(sides[i]) == "modem" then
- modem = peripheral.wrap(sides[i])
- rednet.open(sides[i])
- modemside = (sides[i])
- end
- end
- end
- peripherals()
- --######### USER VARIABLES ############
- local myName = "Slave 1"
- --#####################################
- function startup()
- print("#########BRUM'S SLAVE COMPUTER ############")
- print("Version: " ..version)
- print("Computer ID: " ..myId)
- print("Computer Name: " ..myName)
- print("Modem Side: " ..modemside)
- findMaster()
- end
- function findMaster()
- while connected == false do
- print("INFO: Attempting to find master computer...")
- rednet.broadcast(myName)
- local id, response = rednet.receive(4)
- if response == "hello from master" then
- masterId = id
- print("Successfully Connected to master")
- print("Master computer ID: "..masterId)
- --[[ masterId = tonumber(id) -- try to convert it to a number
- if masterId == nil then
- error("Error: "..masterId .." is not a valid number")
- else
- print("INFO: Successfully converted id to number")
- end
- --]]
- connected = true
- pingMaster()
- else
- sleep(3)
- end
- end
- end
- function pingMaster()
- sleep(10)
- while connected == true do
- print("Pinging master...")
- rednet.send(masterId, "still there?")
- local id, response = rednet.receive(4)
- if id == masterId and response == "Yep! still here." then
- print("INFO: Master responded:" ..response)
- sleep(10)
- connected = true
- else
- connected = false
- end
- end
- end
- sleep(3)
- startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement