component constructor parameters
is there any way to create a component that takes parameters? eg.
the component is only ever constructed by calling
components.addComponent()Solution:Jump to solution
Late but there is a simple way to do it with a macro:
```ts
/** @metadata macro */
export function makeComponent<T>(attributes?: { [key: string]: AttributeValue }, instance?: Instance, id?: Modding.Generic<T, 'id'>) {
const components = Dependency<Components>();...
9 Replies
you mean normal typescript decorator or flamework one?
flamework
create your own Startup method that you will call yourself
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
it probably is, but who cares😋
since these parameters would not be passed to components not created in this manner
Solution
Late but there is a simple way to do it with a macro:
This just takes the component you want to create, whatever attributes you want to attach to it (which should align with the ones it requires) and optionally an instance to attach it to and uses the macro api to get the ID of the component you passed. You could probably also use the passed component to assert required attributes or get intellisense for them but I am too lazy. This is better than explicitly passing parameters to components since the component will not get those parameters if it's just constructed by a preexisting tagged object, and having multiple ways a component can get constructed is confusing. Hopefully this helps anyone searching for an answer
Some horrible thing like this:
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
For my purposes the component either is never removed or is removed by destroying it's instance, alternatively, I also have a remove component macro