Changes

Jump to navigation Jump to search
→‎Common gotchas: rename to best practices, expand a bit
Line 39: Line 39:  
</ol>
 
</ol>
   −
==Common gotchas==
+
==Best practices==
 
<ol>
 
<ol>
 
<li>See [[#When to use Harmony|when to use Harmony]].</li>
 
<li>See [[#When to use Harmony|when to use Harmony]].</li>
 
<li>For crossplatform compatibility, you '''must''' use the code API to register patches. The attribute approach won't work crossplatform.</li>
 
<li>For crossplatform compatibility, you '''must''' use the code API to register patches. The attribute approach won't work crossplatform.</li>
<li>When you patch a method, handle errors and default to the original code. For example:
+
<li>Unhandled errors in a patch can be hard to troubleshoot, which often leads to players asking for help on the SMAPI page instead of your mod. '''Please''' handle errors, log them, and default to the original code. For example:
 
<source lang="C#">
 
<source lang="C#">
 
public class ObjectPatches
 
public class ObjectPatches
Line 60: Line 60:  
         {
 
         {
 
             ...; // your patch logic here
 
             ...; // your patch logic here
             return false;
+
             return false; // don't run original logic
 
         }
 
         }
 
         catch (Exception ex)
 
         catch (Exception ex)
Line 71: Line 71:  
</source>
 
</source>
 
</li>
 
</li>
 +
<li>Use postfixes when possible for best compatibility and stability.</li>
 
<li>Don't use transpile patches unless you have no choice and you know what you're doing. This has a much higher chance of causing issues, is more fragile and likely to break in game updates, and makes it much less likely that other modders can help if you need it.</li>
 
<li>Don't use transpile patches unless you have no choice and you know what you're doing. This has a much higher chance of causing issues, is more fragile and likely to break in game updates, and makes it much less likely that other modders can help if you need it.</li>
 
</ol>
 
</ol>
translators
8,404

edits

Navigation menu