Forum Announcement, Click Here to Read More From EA_Cade.

I need help with my Python script(SOLVED)

Sigma1202Sigma1202 Posts: 40 Member
edited March 5 in Nominated Threads
Can someone tell what I am doing wrong? I have this script
import services
import sims4.commands
from sims.household_utilities.utility_types import UtilityShutoffReasonPriority, Utilities

@sims4.commands.Command('poweron', command_type=sims4.commands.CommandType.Live)
def offgridelectro(_connection=None):

household_id = services.owning_household_id_of_active_lot()
utilities_manager = services.utilities_manager(household_id)
utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip="Power doesn't work off-the-grid")

This shutoffs the power, but it doesn't add the tooltip, and The interactions are not there. What I am doing wrong?

Heres how I want it to look:
HQAhYqH.png

Heres how mine looks:
MCQQpok.png




Post edited by EA_Cade on

Comments

  • TURBODRIVERTURBODRIVER Posts: 68 Member
    Hey!
    You can't provide a tooltip as a string, the game can't process that. The tooltip most likely has to be an Int or a LocalizedString.
    Any test that returns a tooltip will be displayed with a tooltip, but when the tooltip is missing, the interactions will just disappear.
  • Sigma1202Sigma1202 Posts: 40 Member
    Hey!
    You can't provide a tooltip as a string, the game can't process that. The tooltip most likely has to be an Int or a LocalizedString.
    Any test that returns a tooltip will be displayed with a tooltip, but when the tooltip is missing, the interactions will just disappear.

    Ok so I got the key from the string table and converted it from hex to decimal and used that, but that still did not work, so it probably has to be a LocalizedString, the problem is I have no idea what a localizedstring is, this is my first sims 4 script mod, and the info on the internet is kinda scarce, Could you elaborate some more on that?

    pJ20v1R.png

    import services
    import sims4.commands
    from sims.household_utilities.utility_types import UtilityShutoffReasonPriority, Utilities
    
    @sims4.commands.Command('poweron', command_type=sims4.commands.CommandType.Live)
    def offgridelectro(_connection=None):
    
    household_id = services.owning_household_id_of_active_lot()
    utilities_manager = services.utilities_manager(household_id)
    utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip=1740008947)
    

    ps: I also tried just putting it as hex, still nothing

    utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip=0x67B66DF3)



  • Sigma1202Sigma1202 Posts: 40 Member
    Hey!
    You can't provide a tooltip as a string, the game can't process that. The tooltip most likely has to be an Int or a LocalizedString.
    Any test that returns a tooltip will be displayed with a tooltip, but when the tooltip is missing, the interactions will just disappear.

    Ok so I found this function inside someone else's script mod and tried to use it inside my mod, but I get a "TypeError: 'LocalizedString' object is not callable" error, so I am pretty much out of ideas now
    import services
    import sims4.commands
    import sims4.localization
    from sims.household_utilities.utility_types import UtilityShutoffReasonPriority, Utilities
    
    @sims4.commands.Command('poweron', command_type=sims4.commands.CommandType.Live)
    def offgridelectro(_connection=None):
    
    household_id = services.owning_household_id_of_active_lot()
    utilities_manager = services.utilities_manager(household_id)
    tooltip = sims4.localization._create_localized_string(0x67B66DF3)
    utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip=tooltip)
    



  • TURBODRIVERTURBODRIVER Posts: 68 Member
    edited August 2019
    You did use the LocalizedString correctly, I just remembered that tooltips require a callable. Wrapping the tooltip in a return lambda expression or using the LocalizedStringFactory wrapper will do it, something like this:
    import services
    import sims4.commands
    from sims.household_utilities.utility_types import UtilityShutoffReasonPriority, Utilities
    from sims4.localization import TunableLocalizedStringFactory
    
    @sims4.commands.Command('poweron', command_type=sims4.commands.CommandType.Live)
    def offgridelectro(_connection=None):
        household_id = services.owning_household_id_of_active_lot()
        utilities_manager = services.utilities_manager(household_id)
        tooltip = TunableLocalizedStringFactory._Wrapper(0x67B66DF3)
        utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip=tooltip)
    

  • Sigma1202Sigma1202 Posts: 40 Member
    You did use the LocalizedString correctly, I just remembered that tooltips require a callable. Wrapping the tooltip in a return lambda expression or using the LocalizedStringFactory wrapper will do it, something like this:
    import services
    import sims4.commands
    from sims.household_utilities.utility_types import UtilityShutoffReasonPriority, Utilities
    from sims4.localization import TunableLocalizedStringFactory
    
    @sims4.commands.Command('poweron', command_type=sims4.commands.CommandType.Live)
    def offgridelectro(_connection=None):
        household_id = services.owning_household_id_of_active_lot()
        utilities_manager = services.utilities_manager(household_id)
        tooltip = TunableLocalizedStringFactory._Wrapper(0x67B66DF3)
        utilities_manager.shut_off_utility(Utilities.POWER, UtilityShutoffReasonPriority.OFF_THE_GRID, tooltip=tooltip)
    

    Thank you so much, everything works fine now :)

Leave a Comment

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