Posted 22 June 2012 - 11:04 AM
Hi there,
so I had that Idea after reading that help topic where someone asked about receiving a rednet message while using read()
No clue if something like this has been posted before either :P/>/> so tell me if it has been :)/>/>
Also let me know if you have suggestions or find bugs
Version: 0.7.5
Known Issues:
Future Plans:
I might change how to install that at a later version. For now:
Make a file called events with the code:
http://pastebin.com/MWLPr157
Put into startup (at end):
Functions:
events.registerEvent(eventName,eventCallback)
Registers the events and calls the callback function if an event is caught
events.unregisterEvent(registrationID)
Example of how to use it:
so I had that Idea after reading that help topic where someone asked about receiving a rednet message while using read()
No clue if something like this has been posted before either :P/>/> so tell me if it has been :)/>/>
Also let me know if you have suggestions or find bugs
Version: 0.7.5
Known Issues:
- None I've encountered, be sure to report them if you find any.
Future Plans:
- Maybe provide better events (e.g. a redstone event telling the callback function which colors changed and such)
- Add an "all" event
- Add a flag that allows programs to keep their events registered after they close
= Installation =
I might change how to install that at a later version. For now:
Make a file called events with the code:
http://pastebin.com/MWLPr157
Put into startup (at end):
term.clear() term.setCursorPos(1,1)
parallel.waitForAny(function() shell.run("shell") end, function() shell.run("events") end)
os.queueEvent("terminate")
= Usage =
Functions:
events.registerEvent(eventName,eventCallback)
- eventName: string / the name of the event to catch, see wiki for a CC event list
- eventCallback: function to call (arguments: event,p1,p2,p3,p4,p5,p6)
Registers the events and calls the callback function if an event is caught
events.unregisterEvent(registrationID)
- registrationID: the ID returned by events.registerEvent
= Example =
Example of how to use it:
function redstoneCallback()
local cX,cY = term.getCursorPos()
term.setCursorPos(1,cY+1)
term.clearLine()
term.write("Redstone at " .. os.clock())
term.setCursorPos(cX,cY)
end
local regID = events.registerEvent("redstone",redstoneCallback) -- Registers the event
read() -- You can type now and it will print the redstone thingy if it receives a signal change
events.unregisterEvent(regID) -- Unregisters the event
read() -- Now if it receives a redstone signal it will not trigger redstoneCallback() anymore
= ChangeLog =
v0.7.5
- changed from parallel API to own co-routine handling to avoid locking up and missing events
v0.7
- changed arguments of events.unregisterEvent to require regID
- some internal changes
- events of progams that end without unregistering them should now be unregistered
- changeg the code for startup a little
v0.5
- Release