Debugging

From 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

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

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!

Talk to a duck

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

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

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

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.

I'm looking at my first SMAPI log, what is this?!

We have a tutorial on how to read your SMAPI log, with annotated examples!

If using Content Patcher (CP), try getting a patch summary

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.

You may also be interested in the CP troubleshooting guide under the author guide on Github, which covers patch summary and other commands.

If it's a shop using Shop Tile Framework (STF), turn on verbose logging

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

You have a few options:

  • Reproduce the problem again, then exit the game as soon as it happens. That can avoid accumulating thousands of repeating errors in the log.
  • Or open it in a text editor (Notepad or macOS's TextEditor are fine), copy everything from the top to the first few errors, and paste it into the log parser.
  • Or upload it to Pastebin, then copy the Pastebin ID to the log parser site (e.g. https://pastebin.com/kiA3N7Zphttps://smapi.io/log/kiA3N7Zp).

If you have an update notification for a mod but you know you have the latest version

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)

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 Tutorial: How to Add a False Dependency for Load Orders and the Manifest wiki page.

I ventured into modding maps and I have issues!

The map modding wiki page includes a section on potential issues as well as a section on troubleshooting; be sure to check those out for examples of errors and how to fix them. A few examples are also on the tutorial for reading your SMAPI log.

I ventured into creating / editing events and I have issues!

LenneDalben's Event Tips and Tricks page contains a section on common event script issues and how to fix them!

Ask the community

Stardew Valley has a wonderful community of fellow modders. Get links to the Discord and other hangouts at the official wiki. Check out the Asking for Help page, which details some best practices when, well, asking for help.

Got a tip?

Add it here or link to an article describing it!