Jump to content




Using a custom event system


  • You cannot reply to this topic
4 replies to this topic

#1 jaredallard

  • Members
  • 124 posts
  • LocationSeattle, WA

Posted 28 November 2014 - 10:07 AM

To put it simply, is there a way of overwriting the default os event API with your own, that is completely compatible with all the previous events?

#2 Kouksi44

  • Members
  • 89 posts
  • LocationMunich, Germany

Posted 28 November 2014 - 11:23 AM

Well you can overwrite the existing Event functions like os.pullEvent etc.
But I do not know If you can change the whole system ...

#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 28 November 2014 - 11:39 AM

What things do you want to change/add?

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 28 November 2014 - 01:51 PM

as Kouksi44 stated, you can override the os.pullEvent/Raw with your own; example
local oldPull = os.pullEvent
function os.pullEvent( filter )
  local eventData = { oldPull( filter ) }
  if eventData[1] == "some_event" then --# where some_event is one you don't want them to get, or one that your code handles specifically and you don't want them to receive it
    --# do you stuff
    return os.pullEvent( filter ) --# since it's a `hidden event`, you should probably return them a valid event, so just return the next one in the event queue
  end
  return unpack( eventData )
end

--# you program here

--# you should always restore what you override back to what it was before when closing your program
os.pullEvent = oldPull
this would effect all scripts that run during yours.

however all this being said I feel you could be after os.queueEvent.

#5 jaredallard

  • Members
  • 124 posts
  • LocationSeattle, WA

Posted 28 November 2014 - 05:30 PM

@theoriginalbit

My main issue is that I have a function that handles starting new coroutines, then when it yeilds, it stops all other running coroutines aswell as itself, and I presumed os.pullEvent was the issue as it forces it to yeild, but I've found out this isn't true, it's just how lua handles coroutines. Anyways, thanks!

However, the question about whether or not I can access the native events such as peripheral, still stands. Is there a method of manually checking without os.pullEvent/Raw?

Edited by RainbowDashDC, 28 November 2014 - 06:01 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users