Posted 01 January 2014 - 12:26 PM
Hey everybody,
Ive seen the event.listen(name, callback) function in openComputers wiki and wondered if it would be possible to do something similar in CC.
Ive looked around in the forum but couldnt find anything like that and i have no idea how to do it myself.
Could someone briefly explain how to do it, or point me somewhere i can look it up?
Edit:
Nevermind, just found a solution, just forgot about the parallel API. The solution isnt pretty or even usefull since you cant really add event listeners or setup multiple listeners but it works for me, at least for now
Ive seen the event.listen(name, callback) function in openComputers wiki and wondered if it would be possible to do something similar in CC.
Ive looked around in the forum but couldnt find anything like that and i have no idea how to do it myself.
Could someone briefly explain how to do it, or point me somewhere i can look it up?
Edit:
Nevermind, just found a solution, just forgot about the parallel API. The solution isnt pretty or even usefull since you cant really add event listeners or setup multiple listeners but it works for me, at least for now
local event
local callback
function callbackDummy()
while true do
local revent = {os.pullEvent(event)}
callback()
end
end
function eventListener(mainfunc,eventname,callbackfunc)
event = eventname
callback = callbackfunc
parallel.waitForAny(mainfunc,callbackDummy)
end
Edited on 02 January 2014 - 07:19 PM