Difference between revisions of "Crab.onChat()"

From 8x9craft
Jump to: navigation, search
(Examples)
 
(2 intermediate revisions by the same user not shown)
Line 26: Line 26:
 
     }
 
     }
 
});
 
});
crab.handleEvents();
+
while(true){
 +
    crab.sleep(1)
 +
}
 
</source>
 
</source>
  
 
== See also ==
 
== See also ==
 
*[[Crab (API)]]
 
*[[Crab (API)]]

Latest revision as of 02:09, 14 August 2017

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
[2886f84ceca4af0c836545e3] 2024-03-28 10:40:33: Fatal exception of type "Error"

Navigation menu