Runnable Classes¶
Runnable¶
-
class
CommonRunnable
¶ Bases:
sims4communitylib.logging.has_class_log.HasClassLog
,typing.Generic
This class is used when you want to have something reoccurring again and again.
Parameters: context (CommonRunnableContext) – A context containing information about the runnable as well as actions the runnable should perform. -
cancel_stop_reason
¶ A reason for the runnable to be stopped for a cancel reasons.
-
context
¶ A context containing information about the runnable as well as actions the runnable should perform.
-
classmethod
get_log_identifier
()¶ A string identifier for the log of the class.
Note
This is the text that will appear when logging messages.
Returns: The identifier for the log Return type: str
-
classmethod
get_mod_identity
()¶ Retrieve the identity of the mod that owns the class.
Warning
Override this function with the
CommonModIdentity
of your mod.This is a MUST override to allow for proper Exception Handling and Logging!
Returns: An instance of CommonModIdentity Return type: CommonModIdentity Raises: NotImplementedError – Thrown when the function is not implemented.
-
invalid_stop_reason
¶ A reason for the runnable to be stopped for invalid reasons.
-
is_running
¶ The runnable is running.
-
is_starting
¶ The runnable is starting.
-
is_stopped
¶ The runnable is stopped.
-
is_stopping
¶ The runnable is stopping.
-
is_waiting_for_start
¶ The runnable is waiting to start.
-
milliseconds_per_update
¶ The number of milliseconds between updates.
-
restart
(restart_reason, *_, **__)¶ Restart the runnable.
Parameters: restart_reason (Union[int, CommonInt, CommonIntFlags]) – The reason for the restart. Returns: True, if the runnable has been restarted successfully. False, if not. Return type: CommonExecutionResult
-
should_update
(milliseconds_since_last_update)¶ Determine if the runnable should update.
Parameters: milliseconds_since_last_update (int) – The number of milliseconds since the last update. Returns: True, if the update should continue. False, if not. Return type: CommonExecutionResult
-
start
(*_, **__)¶ Start the runnable.
Returns: True, if the runnable has successfully been started. False, if not. Return type: CommonExecutionResult
-
start_after_wait_reason
¶ A reason for the runnable to be stopped after waiting for it to start.
-
stop
(stop_reason, force_stop=False)¶ Stop the runnable.
Parameters: - stop_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the runnable is being stopped for.
- force_stop (bool, optional) – If True, the is_stopping state will not be checked and the runner will be forced to stop. Default is False.
Returns: True, if the runnable has been stopped successfully. False, if not.
Return type:
-
unknown_stop_reason
¶ A reason for the runnable to be stopped for unknown reasons.
-
update
(milliseconds_since_last_update, *_, **__)¶ Update the runnable.
Note
This function is invoked automatically by the runnable itself.
Parameters: milliseconds_since_last_update (int) – The number of milliseconds since the last update. Returns: True, if the update is successful. False, if not. Return type: CommonExecutionResult
-
Runnable With Sims¶
Runnable Context¶
-
class
CommonRunnableContext
¶ Bases:
sims4communitylib.classes.serialization.common_serializable.CommonSerializable
,sims4communitylib.logging.has_class_log.HasClassLog
A context used by a runnable.
-
clear_total_milliseconds
() → None¶ clear_time_since_setup()
Clear the total time passed since the context was set up.
-
clone
(*_, **__)¶ Create a clone of the context.
Returns: A cloned version of this context. Return type: CommonRunnableContext
-
classmethod
deserialize
(data)¶ Deserialize the object from a JSON Serializable form.
Returns: The deserialized form of the object or None if it fails to deserialize. Return type: Union[CommonSerializableType, None]
-
classmethod
get_log_identifier
()¶ A string identifier for the log of the class.
Note
This is the text that will appear when logging messages.
Returns: The identifier for the log Return type: str
-
classmethod
get_mod_identity
()¶ Retrieve the identity of the mod that owns the class.
Warning
Override this function with the
CommonModIdentity
of your mod.This is a MUST override to allow for proper Exception Handling and Logging!
Returns: An instance of CommonModIdentity Return type: CommonModIdentity Raises: NotImplementedError – Thrown when the function is not implemented.
-
initialize
(*_, **__)¶ Initialize the context.
Returns: True, if successful. False, if not. Return type: CommonExecutionResult
-
restart
(restart_reason, *_, **__)¶ Restart the context.
Parameters: restart_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context to be restarted. Returns: True, if successful. False, if not. Return type: CommonExecutionResult
-
serialize
()¶ Serialize the object into a JSON Serializable form.
Returns: A serializable representation of the object. Return type: Union[str, Dict[str, Any]]
-
setup
(*_, **__)¶ Setup the context.
Returns: True, if successful. False, if not. Return type: CommonExecutionResult
-
should_run_on_game_time
¶ Determine if the context should be run using game time or if it should be run using real time.
-
should_track_total_time
¶ Determine if the total time in milliseconds should be tracked. Default is False.
-
should_update
(milliseconds_since_last_update, *_, **__)¶ Determine if the context should update.
Parameters: milliseconds_since_last_update (int) – The number of milliseconds since the last update. Returns: True, if the context should update. False, if not. Return type: CommonExecutionResult
-
teardown
(teardown_reason, *_, **__)¶ Teardown the context.
Parameters: teardown_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context to be torn down. Returns: True, if successful. False, if not. Return type: CommonExecutionResult
-
total_milliseconds
¶ A counter for the total number of milliseconds the context has been running for.
-
update
(milliseconds_since_last_update, *_, **__)¶ Update the context.
Parameters: milliseconds_since_last_update (int) – The number of milliseconds since the last update. Returns: True, if successful. False, if not. Return type: CommonExecutionResult
-
Runnable Context With Sims¶
Runnable Object Context¶
-
class
CommonRunnableObjectContext
(game_object)¶ Bases:
sims4communitylib.classes.runnables.contexts.common_runnable_context.CommonRunnableContext
A context used by a runnable that contains information about an Object.
Parameters: game_object (Union[GameObject, None]) – The game object the context is for. -
game_object
¶ The Game Object this context is for.
-
game_object_id
¶ The decimal identifier of the Game Object this context is for.
-
classmethod
get_log_identifier
()¶ A string identifier for the log of the class.
Note
This is the text that will appear when logging messages.
Returns: The identifier for the log Return type: str
-
classmethod
get_mod_identity
()¶ Retrieve the identity of the mod that owns the class.
Warning
Override this function with the
CommonModIdentity
of your mod.This is a MUST override to allow for proper Exception Handling and Logging!
Returns: An instance of CommonModIdentity Return type: CommonModIdentity Raises: NotImplementedError – Thrown when the function is not implemented.
-