Page MenuHomeFeedback Tracker

Howto easy cooperate between mods?
New, UrgentPublic

Description

When want make interoperability with other mod, for me is best way use preprocessor annotation. Another mod have #define MODNAME and in my mod i am using #ifdef MODNAME....

Preprocessor anntotation can hide code which is not defined when mod is not present.

But this actually not working correct, or we as modders using it wrong way. Sometimes its detect others mod define, sometimes not. Can devs help us howto achieve better interoperability between mods? Nobody want make milions of small mods only for compatibility betweem mod A and mod B. This preprocessor definition will be very useful when works 100%. Not only in .c files but also in .cpp config files.

I think there should be some exception for these defines, to load it first, then all mods will see all definitions from other mods and can easy integrate methods from others mods.

Will be very helpful feature for easy cooperation between mods.

Details

Severity
Feature
Resolution
Open
Reproducibility
Random
Operating System
Windows 7
Category
General

Event Timeline

Hunterz created this task.Jun 30 2021, 4:05 PM

The mod load order as well as script module order 3_Game -> 4_World -> 5_Mission can influence which define is present at which time. In my experience defines work as intended if used correctly. Do you have a minimal example setup where it sometimes works and sometimes does not?

For example from yesterday updated of MuchCarKey I cannot detect this mod in my Carcover. But Helkiana using in his mod same method, just create common folder, which is every time loaded. Before yesterday update of his mod all working smooth.

AXEL7 added a subscriber: AXEL7.Jul 14 2021, 11:15 PM

I am test on 1.12 version this with:

  1. Client-server mod breachingcharge with block define
  2. Only server mod with my code and if def

If i am don't add a 'requiredaddon' #ifdef is not worked, but with added 'requiredaddon' as 'breachingcharge' it is worked ;)

Experimenting today and looks like required addons acts as soft depedency, when requied addon is not present server start without complains. When wants see defines from other mod, must add it to required addons and the are these defines recognized in my mod.

Hmm looks like it works this way only on my local server :/

You should have MOD A and MOD B work separately.
Then when someone wants to use MOD A and MOD B, they should be using a different version which is compatible or a optional add-on version.

You cannot insure a load order without a requiredaddons, so that means you would have to have #ifdef written into both mods.
So for example MOD A would have a #IFDEF MOD_B and MOD B would have #IFDEF MOD_A and then compatibility code.

In Carcover

#IFDEF MuchCarKey
// Code to make compatible
...

in MuchCarKey

#IFDEF Carcover
// code to make comaptibel
...

1.16 again break something which worked before

In much car key mod is inside separate pbo is

#define MuchCarKey

and in Carcover mod I am using

		#ifdef MuchCarKey
		if (!ctx.Read(m_CCIsCKLocked))
			return false;
		
		if (!ctx.Read(m_CCHasCKAssigned))
			return false;
		
		if (!ctx.Read(m_CCCarKeyId))
			return false;
		
		if (!ctx.Read(m_CCCarScriptId))
			return false;
		#endif

That worked more than one year and now is broken. Any idea why ?

maybe only capital letters in name of variable?

hmm #ifdef TRADER also not found it now in 1.16

Liven added a subscriber: Liven.Feb 16 2022, 7:41 AM

@Hunterz can you show your root config.cpp

class CfgPatches
{
	class CarCover
	{
		units[]={};
		weapons[]={};
		requiredVersion=0.1;
		requiredAddons[]=
		{
#ifdef GAMELABS
			"GameLabs_Scripts",
#endif
#ifdef BASICTERRITORIES
			"BasicTerritories",
#endif
			"DZ_Data",
			"DZ_Scripts"
		};
	};
};
class CfgMods
{
	class CarCover
	{
		dir="CarCover";
		picture="";
		action="";
		hideName=0;
		hidePicture=0;
		name="CarCover";
		credits="Hunterz, Lusk-Lynge, Spurgle, Funkdoc";
		author="Hunterz, Lusk-Lynge, Spurgle, Funkdoc";
		overview="$STR_carcover_overview";
		authorID="0";
		version="1.0";
		extra=0;
		type="mod";
		class defs
		{
			class gameScriptModule
			{
				value="";
				files[]=
				{
					"CarCover/Scripts/Common",
					"CarCover/scripts/3_Game"
				};
			};
			class worldScriptModule
			{
				value="";
				files[]=
				{
					"CarCover/Scripts/Common",
					"CarCover/Scripts/4_World"
				};
			};
			class missionScriptModule
			{
				value="";
				files[]=
				{
					"CarCover/Scripts/Common",
					"CarCover/Scripts/5_Mission"
				};
			};
		};
	};
};
class CfgVehicles
{
Liven added a comment.Feb 16 2022, 7:46 AM

The #define MuchCarKey is in "your" CarCover/Scripts/Common?

Second thing, I'm not sure the #ifdef work in the .cpp file (but maybe I'm wrong

no #define MuChCarKey is in Much Car Key mod, this way my mod detecting if much car key mod is present or not

Liven added a comment.Feb 16 2022, 7:55 AM

Ok but you have to add the path to the #define MuChCarKey in your gameScriptModule / worldScriptModule / missionScriptModule (depending where you need it - I usually add the path in each one to be sure) to be able to find it.

sorry but you probably not understand how it works - that #define is defined in Much Car Key mod and I am only detecting using this preprocesor variable if mod is present or not in my mod

and that detection using #ifdef just stopped working again in 1.16

Liven added a comment.Feb 16 2022, 8:01 AM

yes I understand, I often use #define and nerver had problem.
Here is an example of mission path list of my PvZmoD Customisable Zombie that need to detect Dayz_Dog or my other PvZmoD:

class missionScriptModule
			{
				value = "";
				files[] = 
				{
					"Dayz_Dog/Scripts/Common",
					"PvzPanelManager/Scripts/Common",
					"LIVEN/PvZmoD_TheDarkHorde/Scripts/Common",
					"LIVEN/PvZmoD_Spawn_System/Scripts/Common",
					"LIVEN/PvZmoD_CustomisableZombies/Scripts/Common",
					"LIVEN/PvZmoD_CustomisableZombies/Scripts/5_Mission"
				};
			};
Liven added a comment.Feb 16 2022, 8:03 AM

And remember I'm talking about #ifdef in the .c file, I'm not sure they work well in the .cpp

Hunterz added a comment.EditedFeb 16 2022, 8:03 AM

Ahaa you looking in your mod for specific folders from others mods too

interesting, I will try that

Liven added a comment.Feb 16 2022, 8:05 AM

I really think it's how it 's supose to work

Thanks for hint, I will try modify my config according yours example

Liven added a comment.EditedFeb 16 2022, 8:11 AM

Note that I posted a little tuto about #defines on the official forum few days ago :
https://forums.dayz.com/topic/252259-good-modding-practice-add-a-define-to-the-scripts-to-help-other-modders-to-fix-conflicts/

If adding the right path solved your problem can you look at the tuto and tell me if it is clear enough (English is not my natural language)

Hunterz added a comment.EditedFeb 16 2022, 8:24 AM

Oh, many thanks for yours hint, now I am able detect MCK, I did that change in my config.cpp

		class defs
		{
			class gameScriptModule
			{
				value="";
				files[]=
				{
					"MuchCarKeyDefines/scripts/Common",
					"TM/Trader/scripts/defines",
					"CarCover/Scripts/Common",
					"CarCover/scripts/3_Game"
				};
			};
			class worldScriptModule
			{
				value="";
				files[]=
				{
					"MuchCarKeyDefines/scripts/Common",
					"TM/Trader/scripts/defines",
					"CarCover/Scripts/Common",
					"CarCover/Scripts/4_World"
				};
			};
			class missionScriptModule
			{
				value="";
				files[]=
				{
					"MuchCarKeyDefines/scripts/Common",
					"TM/Trader/scripts/defines",
					"CarCover/Scripts/Common",
					"CarCover/Scripts/5_Mission"
				};
			};