Update entrypointlib.lua
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
local pullEvent = os.pullEventRaw
|
||||
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
local network = {}
|
||||
local message_queue = {}
|
||||
modem.open(15125)
|
||||
@@ -24,7 +22,7 @@ end)
|
||||
local last_heartbeat = os.epoch("utc")
|
||||
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
|
||||
|
||||
local function receive()
|
||||
function network.receive()
|
||||
while true do
|
||||
local _, _, channel, _, msg, distance = pullEvent("modem_message")
|
||||
if channel == 15125 then
|
||||
@@ -73,7 +71,7 @@ function network.send(msg,destination)
|
||||
message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0}
|
||||
end
|
||||
|
||||
local function connect()
|
||||
function network.connect()
|
||||
while true do
|
||||
if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then
|
||||
canidate = {id = -1, distance = 764, max_distance=0}
|
||||
@@ -116,9 +114,7 @@ end
|
||||
function network.getCandidate()
|
||||
return canidate
|
||||
end
|
||||
|
||||
function network.loop()
|
||||
parallel.waitForAny(connect,receive)
|
||||
parallel.waitForAll(network.connect,network.receive)
|
||||
end
|
||||
|
||||
return network
|
||||
|
||||
Reference in New Issue
Block a user