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

Recommended Posts

-- Fixed: I was le tired....

 

I'm kinda new to OC just moved over from cc and I'm loving the mod!!

I was curious if someone who knows how event.listen handles its callback function?

I tried to make a simple wireless network port listener just for testing and to my avail i couldnt get it to work the way i intended...

Example below:

local component = require "component"
local event = require "event"

local modem = component.modem

modem.open( 1 )

## I was assuming that event.listen would feed the signal/event with its parameters
## to the callback function.. reason why not? I'm no pro but I figured maybe this was
## overlooked??
local function testfunc( ... )
  print( ... ) -- modem_message and params should print 
end

event.listen( "modem_message", testfunc ) -- Why you no pass params!!

Sorry if this post was out of place.. Any clarification would be nice :) I know there are other ways to do this but i was curious.

  Thanks in advance

 

 

I was being stupid... It was late and I was a tad drunk...Nevermind me :P

Link to post
Share on other sites

 

The event hooks and timers will only get called when event.pull() is called. So you need to add something like

while true do
   event.pull()
end

I fixed my issue above. It was missing :

function testfunc( ... )
  print( table.unpack({ ... }) ) -- this was the issue not the listener
end

I imagine event.pull() is called automatically when using event.listen( event, callback ).

Event listeners will even persist outside of their parent program. Handy for stuff like apis signalling sister programs from the background.

Thanks for the reply.

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
Reply to this topic...

×   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.