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


So, basically what I want to do is make it so that a computer waits for a message to be sent to it, but doesn't get stuck forever waiting for a response. For example, I'd have a computer send a request for data to another computer that's constantly receiving, but the computer that requested the data only listens for responses for 2 seconds, and if it doesn't get anything sent to it, it would result to a default value. 



Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1
local component = require "component"
local modem = component.modem

-- # our majestic default...
local default_value = 42

-- # dont forget to open our ports...

-- # response is a table of either nothing after two seconds, or a modem message.
local response = table.pack(event.pull(2, "modem_message")) -- # wait 2 seconds for a modem message event

-- # Done waiting.. If we got a message, assign the first user sent parameter to it. This is always a string!
if response[1] == "modem_message" and response[5] ~= nil then
  default_value = response[5] -- # The fifth, or greater, parameters hold user set values

Hope this is clear enough to get you started :) 

Share this post

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.

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.


  • Create New...

Important Information

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