Signals are Uni's way of broadcasting and catching events. Entities watch for signals from other entities. Signals may be broadcast by entities when they perform actions.
To watch for a signal broadcast by another entity, use the following code:
var meep = this.world.ent('meep');
ent.watch(this, 'jump', function(data, done){
/*
code for responding to a jump
*/
done.pass();
});
watcher
(ent): the entity that is watching, usuallythis
signal
(str): the name of the signal to be watchedfunction
(fun): the code to be executed when the signal is sentdata
(any): values passed with the signaldone
(obj): callback (done and fail)
Signals are send from inside an action, using the mold. Send a signal to watching entities:
var mold = uni.mold('meep');
mold.act('jump',function(pack,done){
/*
code for jumping
*/
mold.signal(this, 'jump', pack);
});
signaller
(ent): the entity that is signalling, usuallythis
name
(str): name of signal to broadcastdata
(any): payload to send to watchers