useTrait
Call Signature
Section titled “Call Signature”useTrait<
S>(target,trait):DeepReadonly<TraitRecord<S>> |undefined
Koota’s useTrait, which also reads a predicted or a core trait:
target’s record of trait, again each time it changes, or undefined
where it lacks it. A HUD reads a trait of the game’s own with it, such
as useTrait(entity, ScoreTrait)?.points for a
defineTrait("score", { points: 0 }). This signature reads a predicted
or a core trait, and its type makes the record read-only, since only
the step writes one.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends Schema |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
Entity | null | undefined |
trait |
PredictedTrait<S> | CoreTrait<S> |
Returns
Section titled “Returns”DeepReadonly<TraitRecord<S>> | undefined
Call Signature
Section titled “Call Signature”useTrait<
T>(target,trait):TraitRecord<T> |undefined
Any other trait, or a relation’s pair: its record as koota’s useTrait
returns it, which the type does not make read-only.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends Trait |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
World | Entity | null | undefined |
trait |
T | RelationPair<T> |
Returns
Section titled “Returns”TraitRecord<T> | undefined