Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Lab Assistant
Original Poster
#1 Old 10th Mar 2017 at 5:25 AM Last edited by CardTaken : 11th Mar 2017 at 7:43 PM.
Default (resolved) Can't get injector working
I've been banging my head against this for hours and I've more or less narrowed it down to the fact that there must be something wrong with one of the two python scripts I'm using, for injecting.

I'm trying to add an interaction that shows up when you click your sim.

The scripts I'm using are more or less copy/paste, with name and ID changes where it seemed like it made sense to do so at the time. Apart from that, I can't figure out where the heck my error is.

But clearly something is not right and I'm fairly confident it's with the scripts because I tried manually adding my interaction by putting it into the relevant XML file and using that file as an override (with no scripts involved), and when I did that, it showed up just fine. But when I don't use XML override and I try to inject it with python, it's not working.

The code for the python files are as follows.

Injector (named "triplis_child_play_injector")
Code:

# Python function injection
# By scripthoge at ModTheSims
#
from functools import wraps
import inspect

# method calling injection
def inject(target_function, new_function):
@wraps(target_function)
def _inject(*args, **kwargs):
return new_function(target_function, *args, **kwargs)
return _inject

# decarator injection.
def inject_to(target_object, target_function_name):
def _inject_to(new_function):
target_function = getattr(target_object, target_function_name)
setattr(target_object, target_function_name, inject(target_function, new_function))
return new_function
return _inject_to

def is_injectable(target_function, new_function):
target_argspec = inspect.getargspec(target_function)
new_argspec = inspect.getargspec(new_function)
return len(target_argspec.args) == len(new_argspec.args) - 1


Other file (I don't know what you'd call it... the thing that calls the injector)
Code:
import services
import triplis_child_play_injector
import sims.sim

Triplis_Child_Play_sa_instance_ids = (13884954916998690505, )
    
@triplis_child_play_injector.inject_to(sims.sim.Sim, 'on_add')
def Triplis_Child_Play_add_super_affordances(original, self):
    original(self)
    sa_list = []
    affordance_manager = services.affordance_manager()
    for sa_id in Triplis_Child_Play_sa_instance_ids:
        tuning_class = affordance_manager.get(sa_id)
        if not tuning_class is None:
            sa_list.append(tuning_class)
    self._super_affordances = self._super_affordances + tuple(sa_list)

♫ Improvising into a corner ♫
♫ No rhyme or rhythm in this verse cause I'm in a corner ♫
Back to top