https://frankkmods.medium.com/custom-tuning-tests-sims-4-script-modding-3837e214fb68

This is an updated version of a tutorial originally written on Sims 4 Studio.

This tutorial will show you how to create your own tests and test sets, and how to use them in tuning. It is assumed that you are at least somewhat familiar with both tuning and script modding for The Sims 4.

What’s the point?

Vanilla tuning tests cover almost all the bases you’ll ever need, but if you’re creating a larger mod, you’ll notice there are some tests you need that do not exist. Additionally, tests are limited in the logic they can perform: test_globals , for example, can only pass if all of their tests pass. If you need to use OR logic, you’ll have to use a test set — and nesting OR and AND logic in multiple test sets can be a pain.

For example, in my Language Barriers mod, sims can speak different languages, and their proficiency in that language is determined by the presence of a native speaker trait and/or their skill level in that language. In order to figure out if two sims have a particular language level in common, I would have to use one test set per language, in order to determine if they have the native speaker trait or a certain level in its skill. Then, I would have to use another test set to determine if at least one of these test sets passed.

This equates to 10(N+1) test sets, where N is the number of trait/skill pairs. Since there are 6 languages in my mod, this would come out to 70 test sets. No thanks. Using a custom test, I was able to avoid making 70 files, and use something like this for each level instead:

<V t="shared_language_level">
  <U n="shared_language_level">
    <V n="language" t="any_language" />
    <V n="level" t="specific_level">
      <T n="specific_level">10</T>
    </V>
  </U>
</V>

The only caveat to this method is that it requires you to make your own test set that can parse your tests, and then you can reference that test set wherever you need to. But, 10 test sets that can automatically handle the addition of new trait/skill pairs is better than 70 that would need to be manually updated every time you add a new one.

Overview of making your own test

At a high level, making custom tests consists of three scripting steps and two tuning steps. On the scripting side of things, you must:

  1. Create your test class(es)
  2. Create a test set that can parse your tests
  3. Create a test set instance that uses your test set

If you actually want to use your tests in tuning, then:

  1. Create a snippet for your test set instance
  2. Reference your test set snippet in other files

It is also possible to forgo using a standalone test set file if you have other custom tuning files, such as LootActions, modules, etc., but this is beyond the scope of this current tutorial.

How to create a test class