Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Question

I decided to write two programs. One to broadcast whatever you type and another to receive broadcasts.

The one that broadcasts, works perfectly. But the receiving one doesn't. It gets the broadcasts, but doesn't display the how I want. Instead of saying a whole broadcast, it says "modem_message" and the code is shown below.

component = require("component")
event = require("event")
 
print("Pulling broadcasts from port 25565")
 
while true do
 
    os.sleep(.5) --To make sure it doesn't repeat single messages
 
    component.modem.open(25565)
    x = event.pull("modem") --Doing it like this =event.pull("modem") brings errors
    print(x)
 
end
 

Any solution?

Edited by Lizzy Trickster
Code tags :)
Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
  • Solution

Try this
 


local component = require( "component" )
local event = require( "event" )
 
print( "Pulling broadcasts from port 25565" )
component.modem.open( 25565 ) -- only need to open it once
while true do
  -- don't need the sleep in there, event.pull blocks until the signal is detected
  local _, _, from, port, _, message = event.pull( "modem_message" ) -- parts with "_" are not stored
  print( "Got " .. tostring( message ) .. " from " .. from .. " on port " .. port ) 
end

http://ocdoc.cil.li/component:modem for reference

Link to post
Share on other sites
  • 0

maybe because the signal ist called "modem_message", not "modem" like in your event.pull("modem")?

I don't know about that. If you go into the Lua testing prompt and type this in this order as long as you have a network card or wireless network card you can recieve broadcasts, but it shows a whole lot of stuff, including the message.

 

component.modem.open(Port)

=event.pull("modem")

will recieve the next message sent on the port you opened. But I can't do the =event.pull("modem") because it errors with the =

Link to post
Share on other sites
  • 0

Try this

 


local component = require( "component" )
local event = require( "event" )
 
print( "Pulling broadcasts from port 25565" )
component.modem.open( 25565 ) -- only need to open it once
while true do
  -- don't need the sleep in there, event.pull blocks until the signal is detected
  local _, _, from, port, _, message = event.pull( "modem_message" ) -- parts with "_" are not stored
  print( "Got " .. tostring( message ) .. " from " .. from .. " on port " .. port ) 
end

http://ocdoc.cil.li/component:modem for reference

The sleep is only to prevent the message being duplicated, because when I only sent one message, it would come up as several "modem_message" about 4-6 of them, rarely 3. I'm trying it now however to see if it will work, and I was hoping it would be simpler than this :/ rather I thought it would be simpler.

Link to post
Share on other sites
  • 0

No problem :)

 

As for multiple messages, are you sure there are not any loops within the network between the 2 machines you have?

No, I tested it two ways. One with cables, one wirelessly. Both cause several messages. But the .5 second delay fixes it every time. Also I'm glad my post needs to be reviewed thing is gone, I have no patience, at all.

Link to post
Share on other sites
  • 0

No, I tested it two ways. One with cables, one wirelessly. Both cause several messages. But the .5 second delay fixes it every time. Also I'm glad my post needs to be reviewed thing is gone, I have no patience, at all.

 

Hmm, weird. Also yes, after you have 3 approved posts you can post freely. it's mainly there to combat spam accounts

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.