Jump to content

[Tutorial] How to properly handle mod component dependencies


Recommended Posts

Introduction:

The current way of handling mod dependences is relying on DESIGNATED numbers. Due to how DESIGNATED numbers are inseparably connected to the mod components structure and order, it's inevitable that sooner or later those numbers will be changed and all dependencies will have to be updated. And when they do, everything breaks.

Instead of using REQUIRE_COMPONENT, FORBBIT_COMPONENT with DESIGNATED numbers, we will use mod LABEL with combination of MOD_IS_INSTALLED and ID_OF_LABEL as an improved way that won't rely on DESIGNATED numbers and it won't prevent modders from changing them.

Please remember that it's not only about improving your mods, it's also about giving a good example for new modders. The common practice of new people is reading other mod's code to figure out how to do things instead of reading WeiDU documentation.

Q: What is LABEL and why I should add LABEL's to my mods?
A: LABEL is a better DESIGNATED. It allows assigning a unique textual identifier for a given mod component. And use this identifier to handle internal dependencies between the components of the same mod and external dependencies of the mods from different authors. By using globally unique LABEL's locally, you are saving yourself the trouble of fixing dependences after DESIGNATED changes. By using external mods LABEL's for defining dependencies, you avoid 'locking' DESIGNATED numbers changes of those mods so the author can freely change them when he needs to.

Q: I would like to add LABEL's for all my mods so other modders can use it. How to create proper LABEL?
A: Read this guide: What is LABEL, why you should create it and how to do it properly

 

How it was handled before:

  1. mod provide DESIGNATED numbers assigned to it's components
  2. other mods and tools create dependences based on those numbers
  3. after a mod update, the DESIGNATED numbers had to be changed and with it, all mod dependencies need to be updated

How it is handled now:

  1. mod provide globally unique LABEL's assigned to it's components
  2. other mods and tools create dependences based on those LABEL's
  3. even if DESIGNATED numbers will be changed due to the evolution of the mod, their LABEL's won't so all mod dependencies will still be correct

Advantages:

  • using the new way will allow for the dependences to no longer rely on DESIGNATED numbers and survive when they change
  • avoid 'locking' of external mods DESIGNATED numbers changes, author will be able to freely change them when they need

  
Prerequisites:

  • the mod that we want to add dependencies must have LABEL's added to it's components


Example:
Let's consider a NPC mod that has 3 components:

  • the component that add NPC with all it's content into the game
  • the component that allows to change NPC portrait, this component requires main component to be installed
  • the component that allow assigning a special kit from an external mod, this component requires an external mod main component to be installed

NPC.tp2:

 BACKUP "weidu_external\backup\NPC" // move backup folder outside of the main mod data folder
SUPPORT "forum.com/thread-1"
VERSION "0.1.0"

AUTO_EVAL_STRINGS

BEGIN "NPC Main Component" LABEL "NPC-Main" DESIGNATED 1000

    OUTER_SET ID-NPC-Main = ID_OF_LABEL "NPC.tp2" "NPC-Main"
    PRINT "ID of the NPC-Main LABEL: %ID-NPC-Main%"

// Example of local dependency
BEGIN "NPC Portrait Component" LABEL "NPC-Portrait" DESIGNATED 2000
    REQUIRE_PREDICATE MOD_IS_INSTALLED "NPC.tp2" ( ID_OF_LABEL "NPC.tp2" "NPC-Main" ) "This component requires main component."

    OUTER_SET ID-NPC-Main = ID_OF_LABEL "NPC.tp2" "NPC-Main"
    PRINT "ID of the internal NPC-Main LABEL: %ID-NPC-Main%"

    OUTER_SET ID-NPC-Portrait = ID_OF_LABEL "NPC.tp2" "NPC-Portrait"
    PRINT "ID of the internal NPC-Main Portrait: %ID-NPC-Portrait%"

// Example of external dependency
BEGIN "NPC Kit Component" LABEL "NPC-Kit" DESIGNATED 3000
    REQUIRE_PREDICATE MOD_IS_INSTALLED "Kit.tp2" ( ID_OF_LABEL "Kit.tp2" "Kit-Main" ) "This component requires the main component from the external Kit mod."

    OUTER_SET ID-Kit-Main = ID_OF_LABEL "Kit.tp2" "Kit-Main"
    PRINT "ID of the external Kit-Main LABEL from Kit mod: %ID-Kit-Main%"

Kit.tp2 (for reference, must be installed before NPC.tp2):

 BACKUP "weidu_external\backup\Kit" // move backup folder outside of the main mod data folder, change only your mod data folder name
SUPPORT "forum.com/thread-1"
VERSION "0.1.0"

AUTO_EVAL_STRINGS

BEGIN "Kit Main Component" LABEL "Kit-Main" DESIGNATED 9999
    OUTER_SET ID-Kit-Main = ID_OF_LABEL "Kit.tp2" "Kit-Main"
    PRINT "ID of the internal Kit-Main LABEL: %ID-Kit-Main%"

Possible WeiDU improvements:

  • remove the requirement of having '.tp2' for the ID_OF_LABEL tp2 name parameter (for now, you can use a local variable with full tp2 name)
  • add a possibility to use ID_OF_LABEL for REQUIRE_COMPONENT and FORBBIT_COMPONENT so the syntax can be simplified
Edited by AL|EN
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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