The Sims 4 Modern Python Modding: Part 5— Extending Lists

June Hanabi
The Startup
Published in
3 min readSep 27, 2020

--

This is going to be a much easier and shorter tutorial and a bit more fun. You’re going to learn how to extend an in-game list. Extending a list is much safer because it’s often the least likely to conflict with other mods because we’re not replacing anything yet can add additional options or functionality to the entire game.

As briefly mentioned in part 4, there’s an official list of words/strings considered to be “true” and another list for “false”. These 2 lists are used in any command that takes a yes or no / true or false argument. Most mods don’t seem to use the list unfortunately but any that do will automatically be using the extended list. For this tutorial, we’re going to extend both of those lists.

Make sure you start at part 1

The projects here assume your up-to-speed on how to mod for the Sims 4 using python scripting which I already covered in part 1 & part 2.

A note for existing readers

I’ve created a boilerplate / template project to help automate compiling, decompiling, packaging, etc… Link Here. And I tried my best to make it cross-platform and editor agnostic. If you’re about to start a new project and your interested in a template that lays out the groundwork for you then this would be that. Completely optional but there if your interested.

In fact I wrote a whole tutorial on how to use it, link here

Gathering Words

I basically poked around the internet and gathered a large list of words that we’ll be using. Many forms of yes and no are local to your country and area so because I’m in America we’ll be pulling words from there.

Normally though you’d want to have the list in a data file like JSON or XML and have many of them for different countries so that users can extend them themselves and all countries are included and the correct list is loaded based on the language of the player. — However that’s fairly complicated this early in the series so we’re going to shortcut and just pick a country and language. In the future, always keep in mind your audience. You never want to exclude people who may want to use your mod and in 2020 there are many established systems people have come up with related to localization to solve exactly that.

Because the list is very large I’m going to place them in pastebin because I don’t want to fill up the articles with pages of words. You’re welcome to extend the list and add/or remove words.

Link to the list of words.

Adding to the list

We import both the lists of true and false. Also be sure to copy the code here which contains all the words for both lists.

from sims4.commands import BOOL_TRUE, BOOL_FALSE

And then tell python to merge our lists into the official lists

BOOL_TRUE.update(BOOL_TRUE_EXTRA)
BOOL_FALSE.update(BOOL_FALSE_EXTRA)

You’re code should look like this, many entries omitted to keep article size down.

from sims4.commands import BOOL_TRUE, BOOL_FALSEBOOL_TRUE_EXTRA = {
"yup",
"yea",
"yuppers",
...
"you-bet",
"mmhmm",
"way"
}
BOOL_FALSE_EXTRA = {
"nope",
"nuh-uh",
":(",
...
"not-on-my-life",
"not-on-my-watch",
"no-way",
}
BOOL_TRUE.update(BOOL_TRUE_EXTRA)
BOOL_FALSE.update(BOOL_FALSE_EXTRA)

You’re done

That’s it, replacing code is great but extending lists, sets, dictionaries, etc… can open the door for many possibilities and the games code has many lists and such like this. Like I said though, adding to something is often safer then replacing something because 2 mods can both add to something but can’t both replace something. Neither is good or bad though because replacing and extending game code and data opens many doors of possibilities and can make for amazing mods.

Publication to Mod the Sims

This has been accepted into Mod The Sims as a properly packaged mod. Link Here.

Next Part?

Part 6 is available here.

--

--

June Hanabi
The Startup

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