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

Creating Custom Events

Started by St0rm, 28 December 2016 - 06:07 PM
St0rm #1
Posted 28 December 2016 - 07:07 PM
Hey there,
is it possible to create custom events, for example, if i want to get the event of an reactor shutting down or going active(BigReactors API)

reactor = peripheral.wrap("back")
...
local event = os.PullEvent("reactor_change")
doSomething()
Something like that maybe.
My goal is to achieve something similar to the Redstone-Event which is triggered when the Reactor-State changes, so i can send a message via a wireless modem without jamming the channel with an endless loop.
KingofGamesYami #2
Posted 28 December 2016 - 10:22 PM
You can queue events, but you have to manually decide when it should be queued. You cant tie it to a specific value or something.
Bomb Bloke #3
Posted 29 December 2016 - 11:01 AM
That is to say, generally this is the sort of thing the peripheral author would be coding, not a user of their mod.
TheRockettek #4
Posted 29 December 2016 - 12:42 PM
you could just make it check for updates on your reactor after a bit by doing sleeps :P/>
St0rm #5
Posted 29 December 2016 - 07:17 PM
Hmm okay thank you for the answers :)/> I'll try to code something which does not jam the whole channel. If i manage to create something useful i'll post it in this Thread.
St0rm #6
Posted 30 December 2016 - 05:02 PM
Okay i created a function which when run in an parallel works the same as an Event. It does the thing for me, eventhough it really is not difficult … :D/>

status = reactor.getActive()
...
function Reactorevent()
while true do
  if reaktor.getActive() ~= status then
   send()
   status = reaktor.getActive()
  else
   print("Doin Notting!")
  end
  sleep(1)
end

end
Edited on 30 December 2016 - 04:02 PM