The Sims 4 Modern Python Modding: Debugging

June Hanabi
Analytics Vidhya
Published in
5 min readOct 1, 2020

Currently, the only known way at this time to debug is by using PyCharm Pro. Back in Jul 28 of this year, Sigma1202 discovered that PyCharm pro has a package that can be given to running code to add debugging capability and Sigma1202 worked out how to make that happen for The Sims 4.

This is a link to Sigma1202’s video which explains the process.

If you’re not using my boilerplate template then the link above should be easy to follow but an exciting update I made to the boilerplate template is I added the ability to automate most of this. Again, this requires PyCharm Pro which costs money, if you’re not using PyCharm Pro then you have to resort to the older ways of debugging The Sims 4 code.

PyCharm Pro costs money and offers a free-trial if you want to start now and haven't used it before but don’t want to pay for it right now and test to see if it works.

Settings.py

There are a few new settings that have been added.

This is the path to your PyCharm Pro folder. It’s set to the default for version 2020.2.2. In the near future this will likely update so you will probably need to change this soon.

Next we we a few more settings which you can generally leave as-is. It has to install 2 script mods into your game and these settings refer to that.

  • debug_cmd_mod_name Is the mod name which adds the in-game debug command
  • debug_capability_name Is the mod name which adds the debug capability.

There’s an additional setting debug_cmd_mod_src which points to the file that adds the in-game debug command.

There are now 2 new files, debug_setup.py and debug_teardown.py.

debug_setup Compiles, packages, and installs both of the mods.

It offers a clean set of instructions on what to do now. In the game you will find these 2 new mod files.

Like the instructions say, you’re ready to go

Step 1: Create a 'Python Debug Server' configuration In PyCharm Pro from the template using
IDE host name: localhost
port: 5678
Step 2: Select debug profile and begin debugging
Step 3: Load up a playable lot in the game
Step 4: Enter the cheatcode 'pycharm.debug'
Step 5: Switch windows to the debugger and hit resume
Step 6: The game and debugger are now connected, you're ready to start debugging!

Lets follow those first 2 instructions which is prep-work we have to do ourselves. For step 1, we need to add the debug configuration.

Go to Edit Configurations...

Click the + button and click Python Debug Server.

Name it anything you want, set the IDE host name and Port to what was displayed in the message.

Now, lets follow step 2 and start the debugger.

Select your debugger from the list we just made and click the debug icon.

It’s now waiting for the game to reach out and connect so lets follow steps 3–5. Load up a playable lot and type in pycharm.debug into the cheat console.

and switching windows back to the editor, sure enough, there are many error messages

But lets hit resume as instructed

and now more error messages appear which is normal

Lets go back to the game and now we see this message

This tells us we are ready to go. At this point, add breakpoints into your game mod by clicking the space between the line number and the code and a red dot will appear there like in the image below.

This means when the game gets to that line, your mod will freeze, and the debugger will allow you to start debugging. For help on how to debug I recommend searching Google or just playing around and learning.

When you are all done debugging, close the game and stop debugging in the editor by clicking on the stop button.

As stated in the list of steps at the end, call debug_teardown.py when you’re done debugging because otherwise it will just slow down your game.

This removes the 2 debugging mod files. You’re now good to go.

Really happy I started the Boilerplate Project

It’s so nice to just be able to run a script within the same editor that sets up the debugging stuff automatically. I hope you enjoyed it as much as I did. Actual real debugging opens many doors that were otherwise a big pain or impossible without a proper debugger.

I hate that it requires a paid editor in order to do it but it’s all we have right now and it’s much better than the prior alternative.

Thank you again Sigma1202 for figuring this out.

--

--

June Hanabi
Analytics Vidhya

I just love creating art, taking photographs, programming, and teaching new skills to people.