IgorTimofeev / MineOS

Home of MineOS and it's software for OpenComputers mod
Other
754 stars 191 forks source link

I cant run this simple script that broadcasts a message then waits for one #486

Closed LittleTimmy52 closed 1 year ago

LittleTimmy52 commented 1 year ago

It works upuntil it trys to receive a message

error: Captu3re Capture1

code:


local event = require("event")
local m = component.modem -- get primary modem component
m.open(123)
print(m.isOpen(123)) -- true
-- Send some message.
m.broadcast(123, "this is a test")
-- Wait for a message from another network card.
local _, _, from, port, _, message = event.pull("modem_message")
print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
IgorTimofeev commented 1 year ago

local event = require("event")

Event name filtering is OpenOS-only feature. MineOS adheres to the principle of "purity" of libraries without redundant checks, so you have to add them yourself:

while true do
  local eventType, _, from, port, _, message = event.pull()
  if eventType == "modem_message" then
    -- Do something
  end
end

UPD: I should probably create a separate method like event.pullFiltered() that supports specific stuff - that would be a compromise. Although it’s not a fact that someone would open the wiki at all and read about its presence xd