Combining two Mods

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Combining two Mods

Post 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.
Attachments
Hive_Buster_0.3.1.zip
Hive Buster
(557.84 KiB) Downloaded 37 times
Natural_Evolution_Enemies_5.3.2.zip
NE Enemies
(227.9 KiB) Downloaded 35 times

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Combining two Mods

Post by DaveMcW »

Edit: nevermind, orzelek has better answer.
Last edited by DaveMcW on Tue May 31, 2016 8:43 pm, edited 2 times in total.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Combining two Mods

Post 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).

Post Reply

Return to “Modding help”