Re: Event System in STDLIB
Posted: Sat Oct 01, 2016 12:03 am
Slightly branching from the on tick discussion the best use of STDLIB Event is registering multiple handlers for something like this
control - requires scriptA and scriptB
script A and B both have on_build events for different things (or even on_init events etc)
Without the events system you would have a big IF block or for loop in control since calling script.on a second time would overwrite the first one. With STDLIB you can register the on_build in both scriptA and scriptB, essentially keeping all of your scripts separated instead of intermingling them making changes and updates harder. And also you can selectively enable or disable each event handler as needed. Basically treat Event.register the same you would Script.on just with the added feature of more then 1 function per event.
Another area where it REALLY shines is with the GUI stuff (might not be the exact syntax but from the top of my head)
GUI.on_click("Name-of-gui-widget", functiontodo()") is a LOT easier then writing one huge monolithic IF clicked then block for every element with a clickie"
control - requires scriptA and scriptB
script A and B both have on_build events for different things (or even on_init events etc)
Without the events system you would have a big IF block or for loop in control since calling script.on a second time would overwrite the first one. With STDLIB you can register the on_build in both scriptA and scriptB, essentially keeping all of your scripts separated instead of intermingling them making changes and updates harder. And also you can selectively enable or disable each event handler as needed. Basically treat Event.register the same you would Script.on just with the added feature of more then 1 function per event.
Another area where it REALLY shines is with the GUI stuff (might not be the exact syntax but from the top of my head)
GUI.on_click("Name-of-gui-widget", functiontodo()") is a LOT easier then writing one huge monolithic IF clicked then block for every element with a clickie"