Skip to content

Adding networking to support multiple turtles. #17

@SkyTheCodeMaster

Description

@SkyTheCodeMaster

This would be better in a discussion, but they aren't enabled here.

If I wanted to go about adding networking, would I go along the lines of something like:

-- artist/items/network.lua

--- Provides a module to support multiple turtles on a network.
--
local modem = peripheral.find("modem")
-- This probably isn't the best way to find, or exit if there is no modem.
if not modem then return end
modem.open(1) -- Or whatever channel, doesn't really matter

return function(context)
  local disabled = false -- Do not create an infinite loop :)
  context.mediator:add_thread(function()
    while true do
      local _,_,_._,items = os.pullEvent("modem_message")
      disabled = true
      self.mediator:publish("items.change",items) -- This seems right? I'm not sure.
    end
  end)

  context.mediator:subscribe("items.change",function(items)
    if disabled then return end
    -- Now just broadcast the new items? I have no clue how this particular event works.
    modem.transmit(1,1,items)
  end)
end

This is some very rough code, but it should provide an idea of what I'm thinking needs to happen in order to make this work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething which can be improved or added. So everything?

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions