backIndex

Xelagot action script

Events: Chat and messages

Refer to Events for general information on events.

The Xelagots can receive, process and send chat messages through various channels. There is a variety of event handlers and statements to cope with all this messaging. This page has three sections: the first one describes the Chat event used for AW chat, the second one describes the 3.3 Console Message event, the third one has an overview of all events dealing with chat messages.


Chat

The first and most obvious way to communicate is through the world server: that is how we talk and whisper using the AW browser or using bots. To detect and process these messages, you must install an event handler for Chat using the following installer:
OnChatEvent xxx
where xxx is the name of the event handler (event label), and you must define an event handler:
Event xxx
  # some code here
EndEvent

If you wish to stop receiving messages, uninstall the Chat event handler:
OnChatEvent

To install a different Chat event handler, reinstall it this way:
OnChatEvent yyy

Inside this event handler you can retrieve the message and the information about who sent the message, and how it was sent (chat or whisper):

These statements must be inside the Chat event handler. After exiting the event handler, the data may get written over by other events.
GetEventType %e stores the event type code in variable %e. The event types for Chat are:
100 = Chatline was spoken aloud
101 = Chatline was spoken aloud by PS
102 = Chatline was whispered
GetChatLine $a
or
GetMessage $a
stores the chatline in variable $a
GetChatName $n
stores the speaker's name in variable $n
GetChatSession %s stores the speaker's session number in variable %s
GetChatPerson &p stores the speaker's personal data in person variable &p. This does not include the chat line, but includes the name and session number.
IfChatIsSay statement1
Else statement2
tests if the chat event is a 'say' event (EventType 100 or 101). If so, executes statement1; if an Else statement follows, statement2 is executed if the chat is not 'say'.
IfChatIsWhisper statement1
Else statement2
tests if the chat event is a 'whisper' event. If so, executes statement1; if an Else statement follows, statement2 is executed if the chat is not 'whisper'.

The bot can use one of the many Say statements to answer back. If you retrieve the person with GetChatPerson &p, a whole bunch of information becomes available about the person, and the bot can use Whisper to answer back. As from X1 2.9999950 and Av99Bot 1.66, you can use the generic Reply statement.

An example script: when the bot hears "hello" it says or whispers "A good day to you, John" (if the person is called John), if it hears "bye" it answers "Goodbye, John". It will not answer to bots.

[Head]
Type=Script
Version=2.0

[Settings]
Origin=0.000n 0.000w 0.00a 0.0°

[Script]
  OnChatEvent Chat
Label MainLoop
  Goto MainLoop
End

Event Chat
  $b = ""
  GetChatPerson &p
  IfPerson &p IsBot EndEvent
  GetChatName $n
  GetChatline $a
  IfString "hello" IsIn $a $b = "A good day to you, "
  Else IfString "bye" IsIn $a $b = "Goodbye, "
  IfString $b = "" EndEvent
  # IfChatIsSay SayConcat $b $n
  # Else WhisperConcat &p $b $n
  ReplyConcat $b $n
  # ReplyConcat does the same in one line
  # as the two previous lines
  # which are commented out
EndEvent

If you install a Chat event, the chat message first goes to the Chat event handler, and then to the Verbal Command processor in the bot (which uses the dialog file). If no Chat event is installed, the message goes directly to the Verbal Command processor.

To allow more control through scripts, it is possible to disable partially or (almost) totally the application's Verbal Command processor, using these two statements:

ChatImpair %a must be inside the Chat event handler, and must be redefined for every Chat event (it jumps back to 0). The number %a (variable or literal) can have one of the following values:

0, default, does nothing.

1, disables the Verbal Command processor for all except for owners

2, disables the Verbal Command processor for all except for first owners

3, disables the Verbal Command processor for all. If WhisperControl is set to 1, this includes first owners, which retain full control of the bot through whisper
WhisperControl %a Can be anywhere in the script. A value of zero disables whisper control, 1 enables whisper control by the first owners, i.e. the dialog file with all its commands can be used by them when they whisper to the bot.

The Console Message event
x1 3.3

As from world server 39, which is AW 3.3 compliant, Caretakers and Caretaker bots can send a Console Message to individual avatars. This message appears in colour, and can be in bold and italics. To receive this message in the Action Script, you must install a Console Message event handler:
OnConsoleMessageEvent xxx
where xxx stands for an event label

This message does not have a defined sender (although, of course, there is one, as any Caretaker bot can send this message), so you can not ask GetChatName or the like, nor can you reply to it. It is also not processed by the bot's Verbal Command processor.

These statements must be inside the ConsoleMessage event handler. After exiting the event handler, the data may get written over by other events. These are 3.3 statements.
GetEventType %e stores the event type code 8440 in variable %e.
GetChatLine $a
or
GetMessage $a
stores the console message in variable $a
GetMessageColor %r %g %b Retrieves values from 0 to 255 for each of the red, green and blue components of the message colour.
IfChatIsConsoleMessage statement1
Else statement2
tests if the chat event is a 'console message' event (EventType 8440). If so, executes statement1; if an Else statement follows, statement2 is executed if the chat is not 'say'.


Overview of all chat messaging events

Chatting though the world server is but one of the possible ways of sending and receiving messages (Chat event). Historically for Xelagots, the first method I introduced was one that allows communication between bots in the same application, if they are running scripts: the BotChat event. And for the owner to chat with the script through the user interface, I added the BossChat event, now called UIChat event. Both these event handlers work like the Chat event: they intercept the message, which then proceeds to the Verbal Command processor.

When in January 2000 the bots acquired their BotClient software, allowing them to log into a Xelagot server, and the WriteToBot processor was installed in the application, new events appeared. Most of these use the WriteToBot command set to communicate. Using the WriteToBot Hear set to send Verbal Commands, bots in the same application have BotHear and BotAnswer to replace BotChat; using CLWriteToBot Hear, bot clients have CLHear and CLAnswer, and the Av99Bot and SrvcXlgBot processes file requests with DBHear. For security reasons, bots connected to a server must have MASTER protocol to send CLWriteToBot commands, so CLHear only receives messages from a MASTER bot or from a USER (the owner of the bot if s/he has USER protocol). BotHear, CLHear and DBHear trap messages sent with a xxWriteToBot Hear command. These are first trapped by the event handler (if it is installed), and then go to the Verbal Command processor. The Verbal Command processor replies to the sender using a special WriteToBot Answer command, which can only be detected by a bot if it has a BotAnswer and CLAnswer event handler installed: these two event handlers do not pass on the reply to their Verbal Command processor. To complete the series of xxWriteToBot related events, there used to be two more handlers, now obsolete: BotConfirm was used by bots to trap confirmation messages from bots in the same application, CLConfirm trapped them from Bot Clients. These are confirmation messages from WriteToBot commands (excluding replies from the WriteToBot Hear command). For example, the WriteToBot Download sends a confirmation when it has finished downloading a file. These confirmation messages now go to BotAnswer and CLAnswer.

If you do not wish the Verbal Command processor to be involved at all, but wish the bots to freely send messages to each other's scripts, you have three event handlers at your disposal: BotMessage for bots in the same application, CLMessage for Bot Clients, and DBMessage for the file interface (Av99Bot and SrvcXlgBot). These messages have no pre-defined meaning, it is up to the scripts to interpret them.

All these event handlers have similar structure and methods to retrieve information:

Event xxx
   GetEventType %e
   GetChatLine $message
   ## or GetMessage $message
   GetChatName $name
   # your code here   
EndEvent

This means you can install various event handlers using the same handler:

  OnBotAnswerEvent BotChat
  OnBotMessageEvent BotChat
  OnCLAnswerEvent CLChat
  OnCLMessageEvent CLChat

...

Event BotChat
  # $n is the bot's name 
  GetChatName $n
  GetChatline $a
  ...
  # if $b has the answer
  # you can reply
  # using MessageToBot $n $b
EndEvent

Event CLChat
  # $n is the Login name
  GetChatName $n
  GetChatline $a
  ...
  # if $b has the answer
  # you can reply
  # using CLWrite $n $b
EndEvent

To test which type of event a handler is processing, here are a few conditional statements (X1 2.9999950, Av99Bot/SrvcXlgBot 1.66):

IfChatIsSay statement1
Else statement2
Chatline was received in a Chat event (sent by world server) and was said aloud. The script may use GetChatPerson &p and GetChatSession %s
IfChatIsWhisper statement1
Else statement2
Chatline was received in a Chat event (sent by world server) and was whispered to the bot. The script may use GetChatPerson &p and GetChatSession %s
IfChatIsAW statement1
Else statement2
Chatline was received in a Chat event (sent by world server) and was either said aloud or whispered to the bot. The script may use GetChatPerson &p and GetChatSession %s
3.3
IfChatIsConsoleMessage statement1
Else statement2
Chatline was received in a Console Message event (sent by an anonymous Caretaker bot). The script may not use GetChatPerson &p and GetChatSession %s because the sender is unknown. This event was introduced in AW 3.3 and requires a world server and browser that can handle this messaging, and a xelagot 3.3 or higher.
IfChatIsBot statement1
Else statement2
Chatline was received from a bot in the same application, in one of these events: BotMessage, BotChat, BotHear, BotAnswer. The script may use GetChatPerson &p and if the bot is logged into a universe (IfLogginUniverse &p) GetChatSession %s.
IfChatIsUI statement1
Else statement2
Chatline was received from the user interface in a UIChat event (X1 only). The script may not use GetChatPerson &p or GetChatSession %s.
IfChatIsCL statement1
Else statement2
Chatline was received from a Bot Client or a User client (through the bot's own Bot Client), in one of these events: CLMessage, CLHear, CLAnswer. The script may not use GetChatPerson &p or GetChatSession %s.
IfChatIsDB statement1
Else statement2
Chatline was received from a command file in the DB2Bot folder (Av99bot and SrvcXlgBot), in one of these events: DBMessage, DBHear, DBConfirm. The script may not use GetChatPerson &p or GetChatSession %s.
IfChatGoesToVCP statement1
Else statement2
Chatline, after being processed in the event handler, goes to the Verbal Command processor. The event handlers that pass the Chatline to the VCP are: Chat, BotChat, UIChat, BotHear, CLHear and DBHear.

Scripts that send messages to bots in the same application retrieve the data of the bot in this way, if the number %number of the bot (1, 2, 3 ...) or its name $bname is known
GetPerson &bbot %number
GetName $bname %number
GetName $bname &bbot
or using these conditionals:
IfGetBot &bbot %number statement1
IfGetBot &bbot $bname statement1

The peculiarities of these event handlers are described in the following tables.

Event handlers that allow free messages to be passed from bot to bot
event handler triggered by comments
BotMessage
Installer: OnBotMessageEvent xxx
EventType: 8100
message sent by a bot in the same application using:
MessageToBot $bname $message
MessageToBot &bbot $message
Two extra statements may be used in this event handler (similar to Chat event):
GetChatPerson &bot
GetChatSession %s

The message received must be interpreted by the bot script.

The script may reply using:
MessageToBot $name $message
MessageToBot &bot $message
or with the generic
Reply $message
which the receiver must trap in a BotMessage event handler

CLMessage
Installer: OnCLMessageEvent xxx
EventType: 8120
message sent by a Bot Client using:
CLWrite $bname $message

The message received must be interpreted by the bot script.

The script may reply using:
CLWrite $name $message
or with the generic
Reply $message
which must be trapped by a CLMessage event handler

DBMessage
Installer: OnDBMessageEvent xxx
EventType: 8110
DBWriteToBot Message command read from a command file in the DB2Bot folder (Av99Bot and SrvcXlgBot) the script may reply using a DBWriteToBot Message command saved to file in the Bot2DB folder, or with the generic
Reply $message
3.3
ConsoleMessage
Installer: OnConsoleMessageEvent xxx
EventType: 8440
the reception of a Console Message sent by an anonymous Caretaker bot in a 3.3 compliant world. Besides retrieving the message, you can get the color and style:
GetMessageColor %red %green %blue
with values from 0 to 255, and
GetMessageStyle %bold %italics
with 0 meaning absence of bold or italic, non-zero values means presence.

As there is no known sender, the bot can not reply.
Event handlers that pass on the message to the Verbal Command processor (VCP), or receive replies from the VCP.
event handler triggered by comments
Chat
Installer: OnChatEvent xxx
EventType: 100, 101, 102
chat messages sent by a world server see Chat section above
BotChat
Installer: OnBotChatEvent xxx
EventType: 8300
chat messages sent internally by bots in the same application, using:
ChatToBot $bname $Message
ChatToBot &bbot $Message
Two extra statements may be used in this event handler (similar to Chat event):
GetChatPerson &bot
GetChatSession %s

The script may reply using:
ChatToBot $name $message
ChatToBot $bot $message
which is trapped in the receiver's BotChat event handler, but a better solution to avoid possible VCP side effects is to send a MessageToBot, or a generic Reply $message which are trapped in BotMessage.

The VCP replies using ChatToBot, this must be trapped in a BotChat event handler

UIChat
old name: BossChat
Installer: OnUIChatEvent xxx
(old: OnBossChatEvent xxx)
EventType: 8000
Verbal Commands issued through the GUI (X1 only) The script can reply to the screen using:
Secret $message
or SecretConcat ...
or with the generic
Reply $message

(the VCP replies to the screen)

BotHear
Installer: OnBotHearEvent xxx
EventType: 8400
WriteToBot Hear sent by a bot in the same application:
WriteToBot $bname "Hear,message"
WriteToBot &bbot "Hear,message"

The script has no standard way of replying, because this method should be used only to trigger VCP actions. If a reply must be sent, the recommended way is to use the generic Reply $message and trap it in the event handler BotMessage.

The VCP replies must be trapped in a BotAnswer event handler.

BotAnswer
Installer: OnBotAnswerEvent xxx
EventType: 8405
WriteToBot Answer sent by VCP in response to a WriteToBot Hear command, or by bots in the same application.

The script has no standard way of replying. If a reply must be sent, the recommended way is to use the generic Reply $message and trap it in the event handler BotMessage.

CLHear
Installer: OnCLHearEvent xxx
EventType: 8420
CLWriteToBot Hear commands set by Bot Clients having MASTER protocol.

The script has no standard way of replying, because this method should be used only to trigger VCP actions. If a reply must be sent, the recommended way is to use CLWrite or the generic Reply $message and trap it in the event handler CLMessage.

The VCP replies must be trapped in a CLAnswer event handler.

CLAnswer
Installer: OnCLAnswerEvent xxx
EventType: 8430
a special channel used by VCP for answering CLWriteToBot Hear commands, or CLWriteToBot Answer sent Bot Clients with Master protocol.

The script has no standard way of replying. If a reply must be sent, the recommended way is to use CLWrite or the generic Reply $message and trap it in the event handler CLMessage.

DBHear
Installer: OnDBHearEvent xxx
EventType: 8410
DBWriteToBot Hear command read from a command file in the DB2Bot folder (Av99Bot and SrvcXlgBot) replying is not usually needed, the VCP is supposed to do this. If the script must reply, the recommended way is to use the generic Reply $message.
Event handlers for replies to xxWriteToBot commands (excluding xxWriteToBot Hear) OBSOLETE
event handler triggered by comments
BotConfirm
Installer: OnBotConfirmEvent xxx
automatic confirmation of some WriteToBot commands obsolete, use BotAnswer instead. Old code might still work, but setting OnBotConfirmEvent xxx resets OnBotAnswerEvent xxx !!!
CLConfirm
Installer: OnCLConfirmEvent xxx
automatic confirmation of some CLWriteToBot commands obsolete, use CLAnswer instead. Old code might still work, but setting OnCLConfirmEvent xxx resets OnCLAnswerEvent xxx !!!



backIndex