Forum Discussion

Richtofen1202's avatar
6 years ago

I need help with my Python script(SOLVED)

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:
https://i.imgur.com/HQAhYqH.png

Heres how mine looks:
https://i.imgur.com/MCQQpok.png




  • MR_TURBODRIVER's avatar
    MR_TURBODRIVER
    Seasoned Newcomer
    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.
  • MR_TURBODRIVER's avatar
    MR_TURBODRIVER
    Seasoned Newcomer
    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)



  • "TURBODRIVER;c-17201445" wrote:
    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?

    https://i.imgur.com/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)



  • "TURBODRIVER;c-17201445" wrote:
    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)




  • "TURBODRIVER;c-17202353" wrote:
    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 :)