Exception_17 0 Posted February 7, 2023 Share Posted February 7, 2023 I'm trying to make a function which will for example print out the message which was broadcasted by a modem. I'm going to use event.listen, but i dont understand how to get the signal output. Can someone help me? Quote Link to post Share on other sites
0 cadergator10 1 Posted February 8, 2023 Share Posted February 8, 2023 The modem's wiki is here: https://ocdoc.cil.li/component:modem event.listen() returns all the variables given by the event being called. This is the modem's return: local ev, to, from, port, dist, ... = event.pull("modem_message") ev is the event that is returned, which for the modem should equal "modem_message" to is the address of the modem that received it (the wireless network card that is installed on the machine) from is the address of the modem that sent the message port is the port that the message was received on dist is the distance away the computer which sent the message is ... is any other variables that the computer passes. For instance, if you were to run component.modem.broadcast(123,"Hello","World") and your event.pull looked like local ev, to, from, port, dist, message1, message2, message3 = event.pull("modem_message") port would be set to 123, message 1 would equal "Hello", and message2 would equal "World". message3 would just be nil Hope this helped Quote Link to post Share on other sites
0 Exception_17 0 Posted February 8, 2023 Author Share Posted February 8, 2023 3 hours ago, cadergator10 said: The modem's wiki is here: https://ocdoc.cil.li/component:modem event.listen() returns all the variables given by the event being called. This is the modem's return: local ev, to, from, port, dist, ... = event.pull("modem_message") ev is the event that is returned, which for the modem should equal "modem_message" to is the address of the modem that received it (the wireless network card that is installed on the machine) from is the address of the modem that sent the message port is the port that the message was received on dist is the distance away the computer which sent the message is ... is any other variables that the computer passes. For instance, if you were to run component.modem.broadcast(123,"Hello","World") and your event.pull looked like local ev, to, from, port, dist, message1, message2, message3 = event.pull("modem_message") port would be set to 123, message 1 would equal "Hello", and message2 would equal "World". message3 would just be nil Hope this helped So i just make like this:? function f() local _,_,_,_,_,msg = event.pull("modem") print(msg) end event.listen("modem", f()) Quote Link to post Share on other sites
0 cadergator10 1 Posted February 10, 2023 Share Posted February 10, 2023 On 2/8/2023 at 12:25 PM, Exception_17 said: So i just make like this:? function f() local _,_,_,_,_,msg = event.pull("modem") print(msg) end event.listen("modem", f()) That should work. However I think in order to get modem messages the filter has to be "modem_message" instead of "modem". And what that code is going to do is it waits for a modem message. When it receives the message it runs f(), which then waits for another message before printing it out. These should work: while true do local _,_,_,_,_,msg = event.pull("modem_message") print(msg) end and if you really want to use event.listen: function f(_,_,_,_,_,msg) print(msg) end event.listen("modem_message",f) although I wouldn't recommend event.listen unless you have some error handling or checks for interrupting your program in order to remove the listener (listeners persist otherwise until you restart the computer, which can cause some issues) Quote Link to post Share on other sites
0 melanchol_69 0 Posted May 26 Share Posted May 26 I think it is modem now since modem_message wont parse on OC 1.8.x Quote Link to post Share on other sites
I'm trying to make a function which will for example print out the message which was broadcasted by a modem.
I'm going to use event.listen, but i dont understand how to get the signal output. Can someone help me?
Link to post
Share on other sites