Jump to content
Grezvany13

IF-statement within config, possible?

Recommended Posts

I've got a simple yet complex question;

 

Is it possible to use IF-statements within a configuration class (like CfgVehicles or CfgFunctions)?

 

Example:

class CfgVehicles
{
    // always assign ClassA
    class ClassA;

    // only assign ClassB if condition1 is true
    if (condition1) {
       class ClassB;
    };

    // only assign ClassC if condition2 is false
    if (!condition2) {
       class ClassC;
    };
};

The above will (obviously) generate the following error:

ErrorMessage: File CfgVehicles.hpp, line 7: '/CfgVehicles.if': '(' encountered instead of '='

What I would like to do is to include certain (sub-)classes, based on the mods which are (also) enabled, to allow optional mods (in contrast to CfgPatches >> requiredAddons).

 

 

So is there a way to have conditional configs, without adding/removing addons (eg. use separate PBO's, and remove the ones which are not needed)?

 

Of course, as a last resort, I could create separate CfgVehicles files, and use a IF-statement in config.cpp to include the correct one. Although this would mean that I need a separate config for each combination of supported mods...

 

 

Any help and suggestions is appreciated!

Share this post


Link to post
Share on other sites

That doesn't really help, since it's not possible to execute code in a config class.

 

The only thing that might work is using the evil __EVAL function, although

 

 

Some, very few, dialog addons also use this method in their config.cpp's, BUT, in this circumstance, they offer no additional benefit to using #defines. This because an addon is loaded and compiled, once. Bis have attempted to develop dynamic addons and stopped. Should they resurrect it ....

source: https://community.bistudio.com/wiki/Config.cpp/bin_File_Format#Exec.2FEval

 

Of course, in my case the config only needs to run once as well (semi-dynamic), but it still requires some code to be executed within the configs.

Share this post


Link to post
Share on other sites

why do you need IF? Just define both classes... And no it's not possible. A config does not "run" like code. It gets binarized (which replaces all #define and eval things with fixed real config code) during packing. And it gets loaded on game start to permanently stay inside the games memory

Share this post


Link to post
Share on other sites

why do you need IF? Just define both classes... And not it's not possible. A config does not "run" like code. It gets binarized (which replaces all #define and eval things with proper code like specified).

He's talking external mods being enabled (not just his own). Or at least that's how I read it.

Share this post


Link to post
Share on other sites

just define all classes for the different mods then, but make all non-vanilla classes scope 0. Then create additional addon "compatibility addon" where you just set scope 2 for the mod adjustednclasses and scope=0 for vanilla ones - if you have to define it inside the main pbo for some reason.

Share this post


Link to post
Share on other sites

just define all classes for the different mods then, but make all non-vanilla classes scope 0. Then create additional addon where you just set scope 2 for the mod adjustednclasses and scope=0 for vanilla ones.

Other option could be to make seperate pbos for each class from each mod, and in the config in those pbos have required addons for his base pbo and the external mod that the class requires.

Share this post


Link to post
Share on other sites

I my mod I need to inherit classes from other mods, which means that the original class must exist (and therefor the mod must be enabled). But to prevent having dependencies to multiple mods which shouldn't be required (eg. ACE3 is something I want to support, but should never be a dependency), or having 1 + 2n mods (and server keys) which a user has to enable (compatibility mods), I would like to have an optional dependency of third-party mods.

 

So just setting the classes, or changing scopes doesn't work.

Using different PBO's of course isn't an issue (already do that to organise my code), however the moment I put anything in 'requiredAddons' and not load the mod/addon, it won't even start the game since it misses the mod/addon.

 

 

Of course, if it's technically impossible to do what I want, I'll have enough alternative solutions. But it would be nice to get a workable solution, without bothering players (and server admins) with hundreds of mods.

Share this post


Link to post
Share on other sites

That is the intended behavior behind requiredAddons, the point behind it is to put an optionals folder in your mod so players and server admins have free range to enable/disable ACE compat suff or otherwise. Plently of relatively popular mods do this, so it wouldn't be weird for people.

Share this post


Link to post
Share on other sites

That is the intended behavior behind requiredAddons, the point behind it is to put an optionals folder in your mod so players and server admins have free range to enable/disable ACE compat suff or otherwise. Plently of relatively popular mods do this, so it wouldn't be weird for people.

 

I know how it works, and I really hate the fact that mod developers either need to have these optional PBO's or make compatibility mods to be able to work.

 

 

From a developer point-of-view it would be better to have a 'optionalAddons' array (to indicate load-order of mods, without requiring them) and either a way to optionally include configs or have a function like diag_mergeConfigFile (see: https://community.bistudio.com/wiki/Arma_3_Diagnostics_Exe)to override config files through code (and on-the-fly).

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×