Inside Mod Manager v14 Best Practices

From TNG_Wiki
Jump to navigation Jump to search

Mods

  • Prefer the %insert directive over %replace when you have a choice. %replace requires an exact match between the leading white space in the location code and the actual code in the target file. %insert does not. You can avoid a possible bad target error now, or in the future.
  • Keep target Locations code as short as possible while still being unique. The more code contained in your location, the more likely something in there will be changed by TNG or another mod. Using the smallest amount of code reduces the likelihood of a mod being broken this way, potentially requiring a mod update.

Replacing large blocks of text

Your first instinct may be to replace a large block of existing text with a large block of new text. But looking at the best practices, a better approach might be to comment out the existing block and insert the new block right after it. A plus for this approach is that you can see in the script exactly what has been changed.

You can insert an opening comment operator (/* My mod location 2) before the target block using the smallest possible target. And the closing comment plus the new code right after it. This requires two mod config file locations/operations, but any change to the original block, will not cause an error for your mod.

Another approach consists in using a dummy variable as :

// My Mod Code
$dummy_variable = 1;
if ($dummy_variable == 1)
{
do_my_code
}
else {
// My Mod Code
Original code that must be skipped.
} // My Mod Code

Major major target file updates

If your modifications are so extensive as to make the original file unrecognizable, consider replacing it.

Make a copy of the target file and edit all the changes you need there. In the target file at the very top, insert:

include 'my_cust_file.php';
return;
exit;

In effect you are replacing the TNG factory file with yours, but the factory file still exists and will be returned to its original state when the mod is removed.

Important! If the target file defines functions, you will need to remove them from your custom file to avoid "Cannot redeclare function" errors. Thing is, your custom file can still use the functions in the factory file, because even though you bailed out of it early, those functions had already been defined there by the PHP parser.

The final step is to create your mod config file, which inserts the above code in the target file, and copies your customize target file from a support folder into TNG.

If there are addon mods, they can target your customized file, since nothing will happen if they modify the factory file.

TOC

Inside Mod Manager v14 (Home)

  1. Mod Manager and OOP
  2. Mod Manager v14 Concepts
  3. Page Layout
  4. Modules
  5. Directives
  6. Error Handling
  7. Best Practices