Batteryuser
Overview
The batteryuser component allows an entity to act as a consumer of electrical charge. It provides the logic for an entity to interact with and draw power from another entity that possesses a battery component.
Dependencies & Tags
- Tags: Adds the
batteryusertag to the entity upon initialization.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
onbatteryused | function | nil | An optional callback function that is executed before successfully using the battery. It can be used to add custom conditions or side effects. The function receives the user and the battery entity as arguments. |
Main Functions
OnRemoveFromEntity()
- Description: A lifecycle function called when the component is removed from its entity. It cleans up by removing the
batteryusertag. - Parameters: None.
ChargeFrom(charge_target)
- Description: Attempts to draw a single charge from a target entity. This function first checks if the target's
batterycomponent can be used. It then calls the optionalonbatteryusedcallback for additional validation. If all checks pass, it consumes a charge from the target and returns a success status. - Parameters:
charge_target(Entity): The entity instance with abatterycomponent to draw charge from.
- Returns:
result(boolean):trueif the charge was successful,falseotherwise.reason(string): A string explaining why the charge failed, if applicable.