This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jaredallard's profile picture

Using a custom event system

Started by jaredallard, 28 November 2014 - 09:07 AM
jaredallard #1
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?
Kouksi44 #2
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 …
MKlegoman357 #3
Posted 28 November 2014 - 11:39 AM
What things do you want to change/add?
theoriginalbit #4
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.
jaredallard #5
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 on 28 November 2014 - 05:01 PM