Crab.emit()

From 8x9craft
Jump to: navigation, search
function emit(msgType: string, ...args: any[]): void

Make a crab send a custom message to itself.

This function is designed to be used in event handlers after a call to crab.handleEvents().

Custom events will be added to the queue and run in order after current event handler function has finished execution.

Parameters:

msgType: string - type of the message to emit.
...args: any[] - you can pass any number of additional arguments that will be passed down to functions handling this event.

Examples

// Emit an event and handle it.
crab.onChat(function(msg) {
    crab.emit('dance', msg);
    // do some preparations
    crab.say("I'm going to burst into dancing!");
});
crab.on('dance', function(danceName) {
    // dance accordingly
});
while(true){
    crab.sleep(1)
}

See also