Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding networking to support multiple turtles. #17

Open
SkyTheCodeMaster opened this issue Nov 25, 2021 · 1 comment
Open

Adding networking to support multiple turtles. #17

SkyTheCodeMaster opened this issue Nov 25, 2021 · 1 comment
Labels
enhancement Something which can be improved or added. So everything?

Comments

@SkyTheCodeMaster
Copy link
Contributor

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?

@SquidDev SquidDev added the enhancement Something which can be improved or added. So everything? label Mar 2, 2022
@nodlek-ctrl
Copy link

Is this code in a working state? I'm happy to contribute however not sure how to get it running, I tried adding it like a module but I get a few errors, ill look into it a bit more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something which can be improved or added. So everything?
Development

No branches or pull requests

3 participants