Interval Event Handling

Interval Event Registry

class CommonIntervalEventRegistry

Bases: sims4communitylib.services.common_service.CommonService

A registry that will run functions based on an amount of time.

Example usage:
# This is an example showing how you may register your functions to run on intervals.
class ExampleIntervalListener:
    # This function will run only once, after 200 milliseconds have passed. It will then stop listening.
    @staticmethod
    @CommonIntervalEventRegistry.run_once(ModInfo.get_identity().name, milliseconds=200)
    def _example_run_once():
        pass

    # This function will run every 500 milliseconds. It will continue listening until the game is closed or until it is manually unregistered.
    @staticmethod
    @CommonIntervalEventRegistry.run_every(ModInfo.get_identity().name, milliseconds=500)
    def _example_run_every():
        pass
static run_every(mod_identifier, milliseconds=1500)

Register a function to run in intervals of the specified time.

Note

The function will run in intervals every time the amount of time has occurred.

Parameters:
  • mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod registering the listener.
  • milliseconds (int) – The amount of time in milliseconds that must pass before the decorated function will be run.
Returns:

A callable function wrapped that runs in intervals.

Return type:

Callable[.., Callable[.., Any]]

static run_once(mod_identifier, milliseconds=1500)

Register a function to run a single time after a certain amount of time.

Note

A function decorated with this decorator will only run once.

Parameters:
  • mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod registering the listener.
  • milliseconds (int) – The amount of time in milliseconds that must pass before the decorated function will be run.
Returns:

A callable function wrapped to run once.

Return type:

Callable[.., Callable[.., Any]]