Crab.onChat()

From 8x9craft
Revision as of 02:09, 14 August 2017 by Yokmama (talk | contribs) (Examples)
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
[9740d68da2b440d1397a2302] 2024-03-28 22:27:17: Fatal exception of type "Error"

Navigation menu