August 7 - Everyone ready for the Friday Highlight? It's ready for you here!
Are you ready for the The Sims Spark'd? Discuss the final episode here! Don't forget to use spoiler tags! Need a refresher? Click here!

I need help with my Python script(SOLVED)

Sigma1202Sigma1202 Posts: 39 Member
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 Sigma1202 on

Comments

  • TURBODRIVERTURBODRIVER Posts: 56 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.
    Sorry, but not sorry tumblr_paqcr5LaDB1vwgrfio1_r1_75sq.png
  • Sigma1202Sigma1202 Posts: 39 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: 39 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: 56 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)
    

    Sorry, but not sorry tumblr_paqcr5LaDB1vwgrfio1_r1_75sq.png
  • Sigma1202Sigma1202 Posts: 39 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 :)
Sign In or Register to comment.
Return to top