Page 1 of 1

Combining two Mods

Posted: Tue May 31, 2016 6:48 pm
by TheSAguy
Hi,
I'd like to combine two of my mods, but am worried about some code.

Both use a lot of "on_tick" functions and both also have:

Code: Select all

   script.on_event(defines.events.on_tick, nil);
I'm worried that the two fill clash since there are some any same/similar function.
I've attached the two mods if anyone is interested in helping.


It would help if I had a better understanding of how exactly that function worked...
Thanks.

Re: Combining two Mods

Posted: Tue May 31, 2016 8:28 pm
by DaveMcW
Edit: nevermind, orzelek has better answer.

Re: Combining two Mods

Posted: Tue May 31, 2016 8:31 pm
by orzelek
There is a quite simple solution if you are willing to play around a bit.
Create a functions to add/remove handlers for both of mods and make it do following:
1. Register/unregister one common on tick method.
2. Set/reset bool flag to say which handler should be called.

In the common tick method check for flags and call handling as appropriate.

This seems like simpliest solution for this that doesn't involve complex handling mechanics. There is also a library somewhere that tries to handle registering/unregistering of handlers to be executed on tick and handles all the logic (or maybe it was planned not sure atm).