Forum Discussion

richi3f's avatar
6 years ago

Is it possible to load tuning for a custom module?

Hello!

Hopefully someone can help me here. I want to write a new class that has some tunable settings. As soon as these are loaded, I then want to use the values to do something else. However, I have been unable to get the game to read my tuning.

For instance, in the code below ("my_tuning.py") I have a custom class with two tunables: A_NUMBER and A_TRAIT. I set up a command to print the value of MyTuning.A_NUMBER and it's always 0.1 (the value of A_TRAIT is None because I didn't set a default), regardless of the value I specify in the corresponding XML.


from sims4.commands import Command, CheatOutput, CommandType
from sims4.tuning.tunable import Tunable
from traits.traits import Trait

class MyTuning:
A_NUMBER = Tunable(
tunable_type = float,
default = 0.1)
A_TRAIT = Trait.TunableReference()

@classmethod
def _tuning_loaded_callback(cls):
# do stuff with cls.A_NUMBER and cls.A_TRAIT
pass

@Command('test_tuning', command_type=CommandType.Live)
def test_tuning(_connection=None):
output = CheatOutput(_connection)
output(str(MyTuning.A_NUMBER))


This is the XML I'm trying to load (03B33DDF!00000000!F9C4C5D3009CC2E9.my_tuning.Tuning.xml). The guid (17997727520918389481) is the FNV64 of the Python's module name: "my_tuning."





0.8
102448




Is there something I'm missing? Or is loading tuning for modules/classes something that only works for EA classes?

If anyone can help or shed a light in the right direction, it would be greatly appreciated!
  • MR_TURBODRIVER's avatar
    MR_TURBODRIVER
    Seasoned Newcomer
    Hey. I don't know how you structured your directories, so I mainly see inconsistencies that would be causing issues... but you might be right about this only being available for the game itself.

    From what I understand, loading of custom tuning is done by Python itself. On the system init, when the game starts up the python "server", a custom importer is setup. Then that importer is added to the list of module finders which Python uses to load py files. When a module is loaded by Python, it gets processed by the custom importer which checks if variables can be loaded from a tuning file. This means any loaded py file should be processed by the custom importer and filled in with data from a tuning file.

    Unfortunately, it looks like one of the steps is to verify the "tuning roots" of the loaded file. The base game "tuning root" is the folder called "Data" inside of the game files, which makes me believe, only py files from that folder can be loaded by this implementation. I don't see any clean way to "hack" this either. The cleanest way would be to just make your own system, or...

    Just use a snippet. You can create your own snippet tunable instance that loads with the game. It's not as convenient as referring to a class with static variables, because it requires to refer to an instance in an instance manager, but it's something. I do it that way.

    I can't confirm this information without testing, which I don't have time for, but this is all that I can see without actually knowing how the game is supposed to operate.
  • Hey there! Thanks for your detailed reply (and kudos for your awesome mods), it's pretty informative.

    I guess this confirms my suspicions. I did see these functions regarding the tuning roots and the DATA_PATH, but I just wanted to make sure if I was reading things correctly and if maybe someone had done it before as this seems like such a cleaner way to load static variables. But I'll better stick with the snippet.

    :)