Forum Announcement, Click Here to Read More From EA_Cade.

I need help with python, I am losing my mind

Sigma1202Sigma1202 Posts: 40 Member
edited March 5 in Nominated Threads
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.ingredient] += item.quantity - item_count
                unavailable_item_description[item.ingredient] = 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[ingredientDef]) 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.ingredient] += item.quantity - item_count
            unavailable_item_description[item.ingredient] = 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[ingredientDef]) 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

Wb1crhT.png

And here is how my mod version appears in-game

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?
Post edited by EA_Cade on

Comments

  • troshalomtroshalom Posts: 1,095 Member
    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.
    wocka wocka wockaWho gave that puppy asparagus?please do not send me private messages - they creep me out 🤢🤮😱

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file
Return to top