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):DeepReadonly<TraitRecord<T>> |undefined
A world trait, on the world useWorld() hands out: its record, which
the type makes read-only, since a component writes no world trait.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends Trait |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
World | null | undefined |
trait |
T |
Returns
Section titled “Returns”DeepReadonly<TraitRecord<T>> | undefined
Call Signature
Section titled “Call Signature”useTrait<
T>(target,trait):DeepReadonly<TraitRecord<T>> |undefined
Any other trait, or a relation’s pair: its record, its own fields read-only, since a component writes through a writer.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends Trait |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
Entity | null | undefined |
trait |
T | RelationPair<T> |
Returns
Section titled “Returns”DeepReadonly<TraitRecord<T>> | undefined