November 15 - It's Friday, so what do I have for you? A Friday Highlight - here!
November 12 - Everyone ready for November Maxis Monthly? Details here

inject_to causes an last exception(SOLVED)

Sigma1202Sigma1202 Posts: 26 Member
I am probably missing something obvious but I have this script and it's causing a last exception, I think I am injecting it correctly but I might be wrong
import sims.household_utilities.utilities_manager
import injector

@injector.inject_to(sims.household_utilities.utilities_manager, 'shut_off_utility')
def InterceptOffSwitch(original, self, utility, reason, **kwargs):
    original(self, utility, reason, **kwargs)

this part causes a last exception as soon as I load a household, when I remove it I don't get any Le's, I want to add some code after the original EA code, but this alone, without me adding any of my code causes an exception

this is how the original EA method looks:
def shut_off_utility(self, utility, reason, tooltip=None, from_load=False):

What am i missing?

Post edited by Sigma1202 on

Comments

  • TURBODRIVERTURBODRIVER Posts: 51 Member
    Hey. You're injecting into the wrong element, you need to inject into the "HouseholdUtilitiesManager" class.
    Sending the LE file would make it easy to point that out, if you could send it next time.
    Sorry, but not sorry tumblr_paqcr5LaDB1vwgrfio1_r1_75sq.png
  • Sigma1202Sigma1202 Posts: 26 Member
    Hey. You're injecting into the wrong element, you need to inject into the "HouseholdUtilitiesManager" class.
    Sending the LE file would make it easy to point that out, if you could send it next time.

    So I think I am doing it right now, but I am still getting an exception
    @injector.inject_to(sims.household_utilities.utilities_manager.HouseholdUtilitiesManager, 'shut_off_utility')
    def InterceptOffSwitch(original, self, utility, reason, **kwargs):
        original(self, utility, reason, **kwargs)
    

    I am getting an "TypeError: InterceptOffSwitch() takes 4 positional arguments but 5 were given" last exception

    Here's the full exception
  • TURBODRIVERTURBODRIVER Posts: 51 Member
    edited September 15
    Try changing it to something like this instead to avoid problems with the function signature inconsistency.
    @injector.inject_to(sims.household_utilities.utilities_manager.HouseholdUtilitiesManager, 'shut_off_utility')
    def InterceptOffSwitch(original, self, *args, **kwargs):
        original(self, *args, **kwargs)
    
        utility = args[0]
        reason = args[1]
    

    If you're looking to override the arguments, try treating the "tooltip" argument not as a keyword argument. Or you can just change the values in the args variable.
    Sorry, but not sorry tumblr_paqcr5LaDB1vwgrfio1_r1_75sq.png
  • Sigma1202Sigma1202 Posts: 26 Member
    Try changing it to something like this instead to avoid problems with the function signature inconsistency.
    @injector.inject_to(sims.household_utilities.utilities_manager.HouseholdUtilitiesManager, 'shut_off_utility')
    def InterceptOffSwitch(original, self, *args, **kwargs):
        original(self, *args, **kwargs)
    
        utility = args[0]
        reason = args[1]
    

    If you're looking to override the arguments, try treating the "tooltip" argument not as a keyword argument. Or you can just change the values in the args variable.

    This worked, thanks for the help :)
Sign In or Register to comment.
Return to top