Crab.onChat()

From 8x9craft
Jump to: navigation, search
function onChat(callback: Function): void

Set a function as an event listener that is run each time a chat message has been sent by nearby players.

Parameters:

callback: Function - function with signature (message: string, player: Player) => void that gets called after the occurrence of the event.

Examples

// Respond to chat messages from nearby players.
crab.onChat(function(message) {
    if (message == 'Hi') crab.say('Hello');
});
crab.handleEvents();
// Talk only to good-mannered players.
crab.onChat(function(message, player) {
    if (player.getFacing().opposite == crab.getFacing()) {
        crab.say('Hello, ' + player.getName() + '!');
    } else {
        crab.say('Please face me if you want to tell me something!');
    }
});
while(true){
    crab.sleep(1)
}

See also

Navigation menu

Internal error

Jump to: navigation, search
[68b11daf2048e4416cbf63ec] 2024-03-29 15:54:57: Fatal exception of type "Error"

Navigation menu