providefunctionnacatamalon
provide(key: string, value: T) => voidOffers something to the other behaviours on the same object under key, besides what this one
returns under its own name: one word that several behaviours answer to (every one that can be hurt
offers 'health'), or a second thing from one behaviour.
Parámetros
keystringThe word the others ask for it by, with
useScriptApi(key).valueTAnything: usually a small set of functions the others may call.
Ejemplo
registerScript('slime', () => {
let life = 3;
provide('health', { hurt: (n: number) => { life -= n; } });
});
registerScript('spikes', () => {
// Whatever on this object can be hurt, slime or boss.
const health = useScriptApi<{ hurt(n: number): void }>('health');
useUpdate(() => health()?.hurt(1));
});