Forum Discussion

Richtofen1202's avatar
5 years ago

I need help with python, I am losing my mind

So I am injecting into an EA function to add some custom lines of code for my mod

so I copied to original EA function for my injection, I can't use the original() function since I want to add some code in the middle of the function

this is how the original EA function looks, the function is located in Interaction.item_consume.py


def get_test_result(self, sim, cls):
unavailable_items = Counter()
unavailable_item_description = {}
for item in self.ingredients:
item_count = sim.inventory_component.get_item_quantity_by_definition(item.ingredient)
if item_count < item.quantity:
unavailable_items += item.quantity - item_count
unavailable_item_description = item.missing_ingredient_additional_text
if unavailable_items:
tooltip = LocalizationHelperTuning.get_bulleted_list(ItemCost.UNAVAILABLE_TOOLTIP_HEADER(sim), tuple(LocalizationHelperTuning.get_object_count(count, ingredientDef, detail_text=unavailable_item_description) for (ingredientDef, count) in unavailable_items.items()))
return event_testing.results.TestResult(False, "Sim doesn't have the required items in inventory.", tooltip=lambda *_, **__: tooltip)
return TestResult.TRUE


this is how my code looks, the only thing I changed is the "interactions.item_consume.ItemCost().UNAVAILABLE_TOOLTIP_HEADER(sim)" since ItemCost is a Class inside item_consume.py I needed to add the correct path


@inject_to(interactions.item_consume.ItemCostBase, 'get_test_result')
def testing(original, self, sim, cls):
unavailable_items = Counter()
unavailable_item_description = {}
for item in self.ingredients:
item_count = sim.inventory_component.get_item_quantity_by_definition(item.ingredient)
if item_count < item.quantity:
unavailable_items += item.quantity - item_count
unavailable_item_description = item.missing_ingredient_additional_text
if unavailable_items:
tooltip = LocalizationHelperTuning.get_bulleted_list(interactions.item_consume.ItemCost().UNAVAILABLE_TOOLTIP_HEADER(sim), tuple(LocalizationHelperTuning.get_object_count(count, ingredientDef, detail_text=unavailable_item_description) for (ingredientDef, count) in unavailable_items.items()))
return event_testing.results.TestResult(False, "Sim doesn't have the required items in inventory.", tooltip=lambda *_, **__: tooltip)
return TestResult.TRUE


now here's the problem, this is how it's supposed to look in-game

https://i.imgur.com/Wb1crhT.png

And here is how my mod version appears in-game

https://i.imgur.com/xKvKete.png

Now, I am pretty sure the problem lies within the tooltip variable, the first part of the tooltip works fine since it shows my sims name, and the text, so I am pretty sure that the small change that I made is indeed correct, so it would seem to problem lies somewhere after the comma, inside the tuple

now, I haven't changed anything there, so I have no idea why it's not working, I've tried about anything for the whole day, but I am out of ideas now, maybe I am missing something obvious?

Can anyone help?

1 Reply

Replies have been turned off for this discussion
  • I wish my programming skills were up to snuff to help you, and perhaps you have been helped by now. Have you tried reaching out to the folks over at Sims 4 studio?

    Also some other modders at these Discords might be able to assist, but no guarantees:


    Hope that helps.
    Please post back if you were able to get your mod to work or not.

Featured Places

Node avatar for The Sims 4 Mods & Custom Content

The Sims 4 Mods & Custom Content

Find tips, tutorials and troubleshooting for mods and custom content, and The Sims 4 patch files here.Latest Activity: 33 minutes ago
16,503 Posts