Debugging

From The Stardew Modding Wiki
Jump to navigation Jump to search

No matter how simple or clear your code is, somehow there's always something that goes wrong when you first try to run it. Don't worry, that happens to literally every programmer ever. On this page you'll find some tips and other helpful suggestions to try when debugging your mod.

Check your formatting[edit | edit source | hide | hide all]

If your mod uses json files, you can try running them through https://smapi.io/json for a quick check of your brackets and commas. It won't catch everything, but it's faster than loading SMAPI and waiting for red text to appear.

Use Debug Mode[edit | edit source | hide]

Can't figure out what tile you're on or what event is happening? Want to quickly test conditions? Debug Mode is the mod for you!

Ask the community[edit | edit source | hide]

Stardew Valley has a wonderful community of fellow modders. Get links to the Discord and other hangouts at the official wiki.

Talk to a duck[edit | edit source | hide]

No, really! Rubber Duck Debugging is a real thing. Basically, you explain your code to a rubber duck, or your cat, or your mom, or anything/anyone willing to listen. As you do, you will often figure out the problem yourself.

Break it down into steps[edit | edit source | hide]

If you're having trouble with a process, break it down. Don't worry about making sure every aspect of your new crop is right, start by just seeing if you can buy the seeds. If you can't buy the seeds, try adding some Vanilla seeds and seeing if that works. Use giant red rectangles as placeholders to see if your art is doing something; they'll be easy to spot even if they got hidden somehow.

Test multiple conditions at once[edit | edit source | hide]

Can't get an event to trigger? Try creating multiple instances of a short event, such as Clint stopping by the farmhouse door in the morning, and setting the conditions for each one slightly differently. If you see the Clint and Shane events you created but not the Alex event, now you know the problem is in the trigger you used there. Include at least one event that should work absolutely no matter what to make sure your code is working at all.

Challenge your assumptions[edit | edit source | hide]

If you're having a hard time seeing where the issue is, go back to the basics.

Something as simple as, "is the mod / latest version of the mod in the Mods folder?" This is a common issue if you write your mod elsewhere, and then copy that into your Mods folder. You may have updated the copy outside the Mods folder and be going, "I fixed that already though!"

Once you have the location of the latest version of the mod confirmed, "if there are conditions, am I actually remembering them correctly? Is this supposed to trigger in spring / after 6 hearts with Robin / etc.?"

It may seem silly, but challenging the things you assumed you knew can be illuminating. More high level reading on that here.

If using Content Patcher (CP), try getting a patch summary[edit | edit source | hide]

If you're having trouble with a patch in Content Patcher (CP), you can get a patch summary, which has more detail about all the patches it's trying to apply, along with information on whether a patch was applied. To make it easier to find the patch of interest in the summary, make sure you add a LogName field to your patch, like so:
"LogName": "Test dialog Abigail summer Wednesdays 2 hearts"
"Action": "EditData",
"Target": "Characters/Dialogue/Abigail",
"Entries": {
    "summer_Wed2": "This is test dialog!",
}
Then, get the patch summary by:
  1. Load your save and view the content that should be patched (going outside to look at whether a building / map / NPC outfit change, talking to an NPC for dialog, etc.).
  2. Type patch summary full directly into the SMAPI window and press Enter.
  3. Quit the game and upload your SMAPI log to https://smapi.io/log (see instructions on that page).
  4. From there, you can search for your patch using the LogName.

If it's a shop using Shop Tile Framework (STF), turn on verbose logging[edit | edit source | hide]

If you're having trouble adding items to a shop using Shop Tile Framework (STF), it has a verbose logging option in the config you can toggle on. This has extra information you could use to help determine where the failure is happening.

If the log is too big / parser site won't load it[edit | edit source | hide]

If the log is too big, you can open it up in any text editor (Notepad or Notepad++ work; on Mac TextEditor works). Then, copy from the very top of the log to the bottom of the first couple errors, and parse that at https://smapi.io/log

If you have an update notification for a mod but you know you have the latest version[edit | edit source | hide]

If you're seeing a message to update a mod, and you're 100% sure you already have the latest version, it's likely a typo in the version number in the manifest.json file. The message is harmless, but if you want it to go away, you can manually update the version number in the manifest.json file yourself using a text editor like Notepad, or TextEditor on Mac.

If you want to change the load order of 2 mods (set dependencies)[edit | edit source | hide]

It is possible to set a dependency in the manifest.json of a mod you want to load last / win a conflict.

The way the dependencies work, if mod A depends on mod Z, mod Z loads before mod A. That way, mod A wins the conflict. For details on how to set dependencies, see the Manifest wiki page.

Got a tip? Add it here or link to an article describing it!