Jump to content

REQUIRE_COMPONENT a OR b


Recommended Posts

Is it possible to require either of 2 components (let's call them 'a' and 'b') to be installed before installing a third ('c') using the REQUIRE_COMPONENT?  Should I have two subcomponents - one that requires 'a', the other that requires 'b'? But if both 'a' and 'b' are installed, the issue is to make sure only one option is made available so the player doesn't get asked about 'c' twice.  Is this where REQUIRE_PREDICATE comes into play?  However, will it be smart enough to know to uninstall 'c' if 'a' gets uninstalled and 'b' never was installed (or visa versa)?  Or is this something where FORBID_COMPONENT would better suit, like:

BEGIN 'c' REQUIRE_COMPONENT 'a' ...

BEGIN 'c' REQUIRE_COMPONENT 'b' FORBID_COMPONENT 'a' ...

 

Edited by Lauriel
fixed typo
Link to post

I've come up with a different solution.  In the above example, component 'a' was my main component.  Component 'b' was the main component of another mod which does essentially the same thing.  So, in my main component choices, I added the option of just using the other mod's changes.  So now when it comes to the component that requires one or the other ('c'), I can just use REQUIRE_COMPONENT <my tp2> 0 and know that either mine or the other mod's changes are in.

This works fine, however I don't know how it will work if the other mod's main component is uninstalled.  Will it carry over and uninstall my dependent component like it should?  I will have to experiment to find out. 

Link to post

Well, that didn't work.  I guess when you have subcomponents, i.e. options to be selected from for a component, each subcomponent receives it's own number.  So I guess I have to make  subcomponents of my main component FORCED - which I was trying to avoid since it doesn't give you the option to uninstall.  (Yes, I know, I can do it at the command line - but I'm lazy and I don't wanna!)

Is there no other way for me to find out if the main component is installed no matter which of the options was selected?

Link to post

REQUIRE_PREDICATE (MOD_IS_INSTALLED ~mod.tp2~ ~componentA~) OR (MOD_IS_INSTALLED ~mod.tp2~ ~componentB~)

I think.  Never actually tried that.  Otherwise,

Have component A and B both install a dummy marker file, then have component C  REQUIRE_PREDICATE (FILE_EXISTS_IN_GAME ~marker.mrk~)

Link to post
4 minutes ago, subtledoctor said:

REQUIRE_PREDICATE (MOD_IS_INSTALLED ~mod.tp2~ ~componentA~) OR (MOD_IS_INSTALLED ~mod.tp2~ ~componentB~)

I think.  Never actually tried that.  Otherwise,

Have component A and B both install a dummy marker file, then have component C  REQUIRE_PREDICATE (FILE_EXISTS_IN_GAME ~marker.mrk~)

I'll give the REQUIRE_PREDICATE (..) or (..) thingie a shot.  We'll see if it likes that or not and if it does, what happens when the last of the required components is uninstalled.  My guess is nothing, but I'm a cynic at heart.

Link to post
19 minutes ago, Lauriel said:

I'll give the REQUIRE_PREDICATE (..) or (..) thingie a shot.  We'll see if it likes that or not and if it does, what happens when the last of the required components is uninstalled.  My guess is nothing, but I'm a cynic at heart.

Oh me of little faith!  Works perfectly.  THANK YOU!

Link to post

And now - my cynicism is paying off...

I modified the predicate line to look like REQUIRE_PREDICATE (MOD_IS_INSTALLED ~myMod.tp2~ 0) OR (MOD_IS_INSTALLED ~myMod.tp2~ 1) OR ((MOD_IS_INSTALLED ~differentMod.tp2~ 0) AND (MOD_IS_INSTALLED ~myMod.tp2~ 2)) @8

I installed 'differentMod' so it's component 0 was ready to go and I had selected the third option in my mod installation.  So the only portion of the predicate that returned true was OR ((MOD_IS_INSTALLED ~differentMod.tp2~ 0) AND (MOD_IS_INSTALLED ~myMod.tp2~ 2)).  So far so good.

Then I uninstalled 'different Mod' expecting it to NOT reinstall the component with the REQUIRE_PREDICATE defined above...but it did.  I have no idea why it would have thought OR ((MOD_IS_INSTALLED ~differentMod.tp2~ 0) AND (MOD_IS_INSTALLED ~myMod.tp2~ 2)) was true.  It worked fine when it was just a series of 'OR' statements.  As soon as I put in the AND it lost it's little mind.

Any thoughts?

Link to post

It is only a vague sense of mine, but I tend to feel it isn't a great idea to attach too much complicated logic in component predicate requirements.  Once it gets beyond "REQUIRE_PREDICATE ~THIS~ OR ~THAT~" I will generally just switch to using marker files.

Another way to deal with this sort of thing is to abstract away the actual guts of this or that component, tucking it all inside functions (which is recommended anyway).  Basically just throw a "DEFINE_ACTION_FUNCTION do_the_thing BEGIN" at the beginning of your component's code, and an "END" at the end and then move the whole shebang to an external .tpa file.  Then you can put three components into your mod:

BEGIN ~one way to do the thing~
REQUIRE_COMPONENT ~mymod.tp2~ ~0~
DESIGNATED 11

INCLUDE ~mymod/functions.tpa~
LAF do_the_thing END

BEGIN ~another way to do the thing~
REQUIRE_PREDICATE (MOD_IS_INSTALLED ~mymod.tp2~ ~1~)
DESIGNATED 12

INCLUDE ~mymod/functions.tpa~
LAF do_the_thing END

BEGIN ~a third way to do the thing~
REQUIRE_PREDICATE (MOD_IS_INSTALLED ~differentmod.tp2~ ~0~) AND (MOD_IS_INSTALLED ~mymod.tp2~ ~2~) 
DESIGNATED 13

INCLUDE ~mymod/functions.tpa~
LAF do_the_thing END

Only one of those components would ever be valid, so the user will only be asked to install one and they won't even know the difference.  (Might make life a bit annoying for mod managers like PI, but, whatever.)

You can also have more than one REQUIRE_PREDICATE lines for each component; that component 13 above could split the REQUIRE clause into two separate ones, and they effectively do the same work as AND.

Or you can split up different parts of your component into different functions, and call certain functions to do certain things, conditioned on the presence or absence or other mods/components with simple ACTION_IF clauses, which could interact with the overall REQUIRE requirements for bare installation.

Edited by subtledoctor
Link to post
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...