PowerManager
The Power Manager allows you to make your components to be affected by the power system, this include allowing them to receive, give or transmit power.
Callbacks & Custom Data
When you initialise a component into the power system, it will automatically gain the ability to receive data from the callbacks below. Custom components also need custom data along with their initialisation into the power system.
Receiving Type
Any component that requires power via the computer to function.
ComponentClass:sv_onPowerLoss()
Called if the component is a child to the computer when power is lost.
Generating Type
Any component that supplies power to the computers power network.
ComponentClass:sv_receiveUsedPower( usedPower )
Called onFixedUpdate to give the component script the used power of any child power networks.
Parameters:
- usedPower [ number ] The power being used by any child power networks.
battery type
ComponentClass:sv_receiveChargePower( chargePower )
Called onFixedUpdate to give the component script the charge power for the battery type.
Parameters:
- chargePower [ number ] The charge power for the battery type.
The custom type data structure is as follows:
{
chargeRate = 30 -- Number | The power maximum power the battery can charge with.
}
breaker type
ComponentClass:sv_receiveTransferredPower( transferredPower )
Called onFixedUpdate to give the component script the transferred power going through the breaker type.
Parameters:
- transferredPower [ number ] The transferred power through the breaker type.
The custom type data structure is as follows:
{
isActive = true -- Boolean | Whether the breaker type can transfer power or not.
}
Functions
createPowerInstance
sm.scrapcomputers.powerManager.createPowerInstance( shapeId )
Creates a power instance with the given shapeId.
If you have already specified the isPowered boolean as true in toComponent, you will not need to add your component to the power manager with this function.
Arguments:
- shapeId [ integer ] The shape id of the component you wish to add to the power system.
createCustomComponent
sm.scrapcomputers.powerManager.createCustomComponent( shape, type_, data )
Creates a custom specified power component for components that do more than just supply or demand.
Arguments:
- shape [ Shape ] The shape you wish to create as a custom power component.
- type_ [ string ] The custom component type, currently the only types are:
breakerandbattery. Each custom type has its respective attributes detailed in Callbacks & Custom Data. - data [ table ] The table of custom data to pass into the instance.
Returns:
updateCustomComponent
sm.scrapcomputers.powerManager.updateCustomComponent( shapeId, data )
Updates the custom data of a custom component.
Arguments:
- shapeId [ integer ] The shape id of the custom component.
- data [ table ] The updated data, see Callbacks & Custom Data for details.
updatePowerInstance
sm.scrapcomputers.powerManager.updatePowerInstance( shapeId, powerPoints )
Updates the power required / generated by a power component.
Arguments:
- shapeId [ integer ] The shape id to update.
- powerPoints [ number ] The updated power points, default after initialisation is 0.
removePowerInstance
sm.scrapcomputers.powerManager.removePowerInstance( shapeId )
Removes a component from the power manager, should be done when the component no longer needs to be affected by the power manager.
If you have already specified the isPowered boolean as true in toComponent, you will not need to manually remove the component from the power manager.
Arguments:
- shapeId [ integer ] The shape id to remove.
isEnabled
sm.scrapcomputers.powerManager.isEnabled()
Returns true if the power manager is enabled.
Returns:
- [ boolean ] Whether the power manager is enabled or not.