Skip to main content

ComponentManager

Manages components and lets you create components.


Functions

toComponent

sm.scrapcomputers.componentManager.toComponent( classData, componentType, isAComponent, automaticRefreshGen, isPowered )

Hooks your class so you can create components easly. For addon developers, this is required to be called on all of your components and interactables.

  • For components: All variables must be used, isAComponent would be true.
  • For Interactables: Same for components but you can set componentType to nil and isAComponent to false.

Arguments:

  • classData [ ShapeClass ] The interactable's (or component) class.
  • componentType [ string ] The type of component, Make sure this does not be a conflict with other addons or the mod itself!
  • isAComponent [ boolean ] Set this to true if your interactable is a component!
  • automaticRefreshGen [ boolean? ] If this is nil or true, It will generate onRefresh Functions. (Defaults to true)
  • isPowered [ boolean ] Whether the component supplies or recieves power via the power system or not.
Note:

For your component to behave as a generating component, the 'componentType' argument needs to be the string PowerComponents. If it is not a custom object, any other 'componentType' will result in a component that can only recieve power.

How to use this function

If you do not know how to use this function, this short guide will help you.

Add this:

-- For Components
sm.scrapcomputers.componentManager.toComponent( yourClass, "YourComponentType", true, false|true )

-- For Interactables
sm.scrapcomputers.componentManager.toComponent( yourClass, "YourComponentType", false, false|true )

-- DO NOT ADD ANY FURTHER CODE BELOW HERE!

getComponents

sm.scrapcomputers.componentManager.getComponents( componentType, interactable, viaChildren, flags, getPrivateData )

Gets all connected components of the interactable and returns it.

Arguments:

  • componentType [ string ] The component type to get.
  • interactable [ Interactable ] The interactable to search through.
  • viaChildren [ boolean ] If it should get components via children or parents.
  • flags [ integer? ] The flags to use to get the components.
  • getPrivateData [ boolean? ] Access private data for components (any data with SC_PRIVATE at the start)

Returns:

  • [ table ] All connected components it has discovered.