Difference between revisions of "Bot Playground/Events/instant message"

From SmartBots Developers Docs
Jump to: navigation, search
(Add note about speaker distance appearing NULL when only just appeared.)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
+
{{DISPLAYTITLE:instant_message}}
 
<onlyinclude>Fires when bot receives a message from another avatar or in-world object.</onlyinclude>
 
<onlyinclude>Fires when bot receives a message from another avatar or in-world object.</onlyinclude>
 +
 +
<syntaxhighlight lang="javascript">
 +
Bot.on("instant_message", function(event) { ... });
 +
</syntaxhighlight>
  
 
{{API Event Table}}
 
{{API Event Table}}
{{API Variable Group|Output}}
+
{{API Variable Group|''event'' object properties}}
 +
{{API Variable|name}}The name of the event in this case instant_message
 +
{{API Variable|speaker_type}}The sender of the message. Can be AVATAR or OBJECT
 +
{{API Variable|speaker_name}}The name of the sender
 +
{{API Variable|speaker_uuid}}The UUID of the sender
 +
{{API Variable|object_uuid}}The UUID of the object
 +
{{API Variable|speaker_distance}}The distance to the sender in metres (works only for speaker_type of AVATAR)
 +
{{API Variable|speaker_x}}The x position in region of the sender (works only for speaker_type of AVATAR)
 +
{{API Variable|speaker_y}}The y position in region of the sender (works only for speaker_type of AVATAR)
 +
{{API Variable|speaker_z}}The z position in region of the sender (works only for speaker_type of AVATAR)
 
{{API Variable|message}}The text of the message
 
{{API Variable|message}}The text of the message
  
 
{{API Variables Table End}}
 
{{API Variables Table End}}
  
== Comments ==
+
== Speaker distance and coordinates ==
 +
 
 +
This event also returns <code>speaker_distance</code>, <code>speaker_x</code>, <code>speaker_y</code>, <code>speaker_z</code> so that you can determine their position. It is important to note that these parameters may return NULL if the bot or speaking avatar has only just appeared in-world.
 +
 
 +
== Example ==
 +
 
 +
<syntaxhighlight lang="javascript">
 +
Bot.on("instant_message", function(event) {
 +
console.log(event.speaker_name + " says: \n" + event.message);
 +
});
 +
 
 +
console.log("Bot is listening, IM something");
 +
</syntaxhighlight>
 +
 
 +
{{NavMenu}}

Latest revision as of 14:14, 22 September 2025

Fires when bot receives a message from another avatar or in-world object.

Bot.on("instant_message", function(event) { ... });

Reference

This event comes with the following event object:

Variable Required Description
event object properties:
name The name of the event in this case instant_message
speaker_type The sender of the message. Can be AVATAR or OBJECT
speaker_name The name of the sender
speaker_uuid The UUID of the sender
object_uuid The UUID of the object
speaker_distance The distance to the sender in metres (works only for speaker_type of AVATAR)
speaker_x The x position in region of the sender (works only for speaker_type of AVATAR)
speaker_y The y position in region of the sender (works only for speaker_type of AVATAR)
speaker_z The z position in region of the sender (works only for speaker_type of AVATAR)
message The text of the message

Speaker distance and coordinates

This event also returns speaker_distance, speaker_x, speaker_y, speaker_z so that you can determine their position. It is important to note that these parameters may return NULL if the bot or speaking avatar has only just appeared in-world.

Example

Bot.on("instant_message", function(event) {
	console.log(event.speaker_name + " says: \n" + event.message);
});

console.log("Bot is listening, IM something");