Modding:Modder Guide/Test and Troubleshoot: Difference between revisions
imported>Pathoschild + basic page |
imported>Pathoschild + common build warnings from Modding:Migrate to Stardew Valley 1.3 (only author is Pathoschild) |
||
| Line 3: | Line 3: | ||
This page helps solve common issues when creating mods. '''For issues ''using'' mods, see [[Modding:Player Guide/Troubleshooting]].''' | This page helps solve common issues when creating mods. '''For issues ''using'' mods, see [[Modding:Player Guide/Troubleshooting]].''' | ||
==Fix common | ==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 [https://msdn.microsoft.com/en-us/library/ms185328.aspx 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 fields|net field]], which can cause subtle bugs. The field you're referencing has an equivalent non-net property, like <tt>monster.Health</tt> (<tt>int</tt>) instead of <tt>monster.health</tt> (<tt>NetBool</tt>). 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 fields|net field]], which can cause subtle bugs. You should access the underlying value instead: | |||
<ul> | |||
<li>For a reference type (i.e. one that can contain <tt>null</tt>), you can use the <tt>.Value</tt> property (or <tt>.FieldDict</tt> for a <tt>NetDictionary</tt>): | |||
<source lang="c#"> | |||
if (building.indoors.Value == null) | |||
</source> | |||
Or convert the value before comparison: | |||
<source lang="c#"> | |||
GameLocation indoors = building.indoors.Value; | |||
if(indoors == null) | |||
// ... | |||
</source></li> | |||
<li>For a value type (i.e. one that can't contain <tt>null</tt>), check if the parent is null (if needed) and compare with <tt>.Value</tt>: | |||
<source lang="c#"> | |||
if (item != null && item.category.Value == 0) | |||
</source></li> | |||
</ul> | |||
===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. | |||
==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:01, 1 June 2018
- Get started
- Game fundamentals
- Test & troubleshoot
- Release
- API reference
- Basic SMAPI APIs:
- Advanced SMAPI APIs:
- Specific guides
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.
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!