Skip to content

is async os.pullEvent() possible? #1237

Answered by fatboychummy
C4PTRAMPAGE asked this question in Q&A
Discussion options

You must be logged in to vote

So you can do this one of two ways. I personally like the second method a bit better.

Multi-event pulling

Basically, you don't apply a filter to os.pullEvent(), then use an if statement on the event returned to separate what you want to do.

Example

while true do
  local event_data = table.pack(os.pullEvent())
  -- event name is stored as event_data[1]
  
  if event_data[1] == "monitor_touch" then
    -- act on the monitor touch
  
    -- you can do the following if you wish to separate out the values returned by os.pullEvent as well:
    local monitor_touched, x, y = table.unpack(event_data, 2, event_data.n)
    
  elseif event_data[1] == "rednet_message" then
    -- act on the rednet mes…

Replies: 5 comments 9 replies

Comment options

You must be logged in to vote
2 replies
@C4PTRAMPAGE
Comment options

@Lupus590
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Lupus590
Comment options

@SquidDev
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@C4PTRAMPAGE
Comment options

@C4PTRAMPAGE
Comment options

@fatboychummy
Comment options

@C4PTRAMPAGE
Comment options

@fatboychummy
Comment options

Answer selected by C4PTRAMPAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants