Difference between revisions of "Modding:Modder Guide/Test and Troubleshoot"

From Stardew Valley Wiki
Jump to navigation Jump to search
(+ common build warnings from Modding:Migrate to Stardew Valley 1.3 (only author is Pathoschild))
(→‎Fix common build warnings: + "An instance of analyzer ... cannot be created" (main authors are Mralbobo and Pathoschild))
Line 42: Line 42:
  
 
You're referencing a field which should no longer be used. Use the suggested field name instead to fix it.
 
You're referencing a field which should no longer be used. Use the suggested field name instead to fix it.
 +
 +
===An instance of analyzer ... cannot be created===
 +
Update to the latest [https://www.visualstudio.com/vs/community/ Visual Studio 2017]; the NuGet package uses a recent feature that isn't available in older versions.
  
 
==Ask for help==
 
==Ask for help==
 
If you still need help, ask for help in [[Modding:Community#Discord|#modding on the Stardew Valley Discord]]. The Stardew Valley modding community is very welcoming!
 
If you still need help, ask for help in [[Modding:Community#Discord|#modding on the Stardew Valley Discord]]. The Stardew Valley modding community is very welcoming!

Revision as of 23:05, 1 June 2018

Creating SMAPI mods SMAPI mascot.png


Modding:Index

This page helps solve common issues when creating mods. For issues using mods, see Modding:Player Guide/Troubleshooting.

Fix common build warnings

Make sure you check your Error List pane in Visual Studio (or equivalent in other IDEs) and fix any warnings. Here are some common ones:

Mismatch between the processor architecture...

Sample warning: "There was a mismatch between the processor architecture of the project being built "{0}" and the processor architecture of the reference "{1}". This mismatch may cause runtime failures."

That warning is normal. The error is saying that your build is set to 'Any CPU', but Stardew Valley is x86-only so it'll only work in x86 anyway. You can either ignore it, or change your platform target to x86.

This implicitly converts...

Sample warning: "This implicitly converts '{0}' from Net{1} to {2}, but Net{1} has unintuitive implicit conversion rules. Consider comparing against the actual value instead to avoid bugs. See https://smapi.io/buildmsg/avoid-implicit-net-field-cast for details."

Your code is referencing a net field, which can cause subtle bugs. The field you're referencing has an equivalent non-net property, like monster.Health (int) instead of monster.health (NetBool). Change your code to use the suggested property instead.

FieldName is a Net* field...

Sample warning: "'{0}' is a Net{1} field; consider using the {2} property instead. See https://smapi.io/buildmsg/avoid-net-field for details."

Your code is referencing a net field, which can cause subtle bugs. You should access the underlying value instead:

  • For a reference type (i.e. one that can contain null), you can use the .Value property (or .FieldDict for a NetDictionary):
    if (building.indoors.Value == null)
    

    Or convert the value before comparison:

    GameLocation indoors = building.indoors.Value;
    if(indoors == null)
       // ...
    
  • For a value type (i.e. one that can't contain null), check if the parent is null (if needed) and compare with .Value:
    if (item != null && item.category.Value == 0)
    

The FieldName field is obsolete...

Sample warning: "The 'Character.friendships' field is obsolete and should be replaced with 'friendshipData'. See https://smapi.io/buildmsg/avoid-obsolete-field for details."

You're referencing a field which should no longer be used. Use the suggested field name instead to fix it.

An instance of analyzer ... cannot be created

Update to the latest Visual Studio 2017; the NuGet package uses a recent feature that isn't available in older versions.

Ask for help

If you still need help, ask for help in #modding on the Stardew Valley Discord. The Stardew Valley modding community is very welcoming!