Jump to content




modem_message returns table instead of message

peripheral wireless

7 replies to this topic

#1 resdac

  • Members
  • 6 posts

Posted 09 August 2015 - 10:56 PM

the problem goes as folows. have this on pc 1
rednet.open("top")
rednet.broadcast("hello")
and this on pc 2
local oldpull=os.pullEvent
os.pullEvent = os.pullEventRaw
print("receiver")
wifi = peripheral.wrap("right")
wifi.open(65535)
while true do
	local event, value1, value2, value3, value4, value5 = os.pullEvent()
	print(event)
	print(value1)
	print(value2)
	print(value3)
	print(value4)
	print(value5)
end
if i start both up the second pc gives me instead of the plain hello
on the 4th value this: table: 2690b665
the value inside the table switches with every message

why is the second pc not giving me a rednet_message instead of the modem_message
and why is the message transformed into a table?

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 09 August 2015 - 11:15 PM

1. Rednet sends "formated" messages now. They are tables containing some stuff like your message.

2. You should either add a filter to pullEvent or make an infinite loop and only react to modem_message events. Otherwise your pullEvent call will react to anything.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 09 August 2015 - 11:44 PM

Rather, you'd want to filter for rednet_message events, ignoring modem_message events.

local event, value1, value2, value3, value4, value5 = os.pullEvent("rednet_message")


#4 Anavrins

  • Members
  • 775 posts

Posted 10 August 2015 - 02:30 AM

Either that, or you could get the message with "event4.message"

#5 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 10 August 2015 - 03:12 AM

View PostBomb Bloke, on 09 August 2015 - 11:44 PM, said:

Rather, you'd want to filter for rednet_message events, ignoring modem_message events.

local event, value1, value2, value3, value4, value5 = os.pullEvent("rednet_message")

Why? That still leads to the same problem. Rednet sends the tables, not the modem API. And the OP is listening on the broadcast channel...

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 10 August 2015 - 03:53 AM

Er, what?

The modem API is always used send the messages - full stop. This is the case whether you're using the rednet API as a wrapper for it or otherwise.

If you're using the rednet API, and have at least ComputerCraft 1.6, then rednet.send() encapsulates the message within a table before passing it to the modem API for transmission. The receiving system detects the resulting modem_message event via rednet.run() (which runs in a coroutine separate to whatever else the user has the system doing), and that queues a rednet_message event using the message within the table.

That said, you can send tables as messages, if you want. But if no table was in the original message passed to rednet.send(), then no table will exist within the final rednet_message event, either.

The reason that no rednet_event messages are appearing at all is because rednet.run() only performs these event translations if the broadcast port and the port equal to the computer's ID number are open. So yeah, something like this would also need to be added to the receiver script:

wifi.open(os.getComputerID())


#7 resdac

  • Members
  • 6 posts

Posted 10 August 2015 - 11:38 AM

View PostAnavrins, on 10 August 2015 - 02:30 AM, said:

Either that, or you could get the message with "event4.message"
thanks this fixes the problem, opening the modem with the computer id wasn't a good option cause i am still looking for other events like the key event and mouse event for advanced pc's

#8 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 10 August 2015 - 12:06 PM

View PostBomb Bloke, on 10 August 2015 - 03:53 AM, said:

Er, what?

The modem API is always used send the messages - full stop. This is the case whether you're using the rednet API as a wrapper for it or otherwise.

If you're using the rednet API, and have at least ComputerCraft 1.6, then rednet.send() encapsulates the message within a table before passing it to the modem API for transmission. The receiving system detects the resulting modem_message event via rednet.run() (which runs in a coroutine separate to whatever else the user has the system doing), and that queues a rednet_message event using the message within the table.

That said, you can send tables as messages, if you want. But if no table was in the original message passed to rednet.send(), then no table will exist within the final rednet_message event, either.

The reason that no rednet_event messages are appearing at all is because rednet.run() only performs these event translations if the broadcast port and the port equal to the computer's ID number are open. So yeah, something like this would also need to be added to the receiver script:

wifi.open(os.getComputerID())

Oh. Sorry, I messed some stuff up. It's not a good idea to write answers in AaP late at night...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users