backIndex

Xelagot action script

Events

What must you do if you want the bot to react to unpredictable things, like chat, avatars entering, moving, clicking, departing, or disconnection? For predictable things, you use Goto and Gosub to re-direct the flow of the script. For unpredictable things you use event handlers: the bot itself decides when to jump to an event handler, you do not use Gosubs for that.

The bot is event-driven. Events happening in AW (chat, detection of movement etc) are trapped by the main program and can also be trapped by scripts. To do so, you must define and install an event handler:

An event handler is defined after the End statement of the script, in the same region you define the Subs (it is, in fact, a special kind of sub). The syntax is:

Event <eventlabel>
#your code here
EndEvent
You can define various event handlers for the same event. These can be used a different moments in the script, but only one can be used at any time. To use an event handler you defined, you need to install it at an appropriate place in the script. This can be anywhere, in the main part, in a Sub or in an event handler.

To install the event handler, you will need to specify the sort of event you are trapping and the event handler, using an installer. For example, for the chat event you would write:

OnChatEvent <eventlabel>
To uninstall an event handler, omit the eventlabel.
OnChatEvent
You can switch handlers for an event, just re-install it to another eventlabel.

Each event has a type, defined in GetEventType %e. See each event section for this code. Each event has also a GetEventResult %r code, identical in most cases to the SDK rc code: 0 indicates success. In some event types this code will always be 0.

Example:

[Head]
Type=Script
Version=2.0

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

[Script]
   WhisperControl 1
   OnChatEvent BotChat
   Label Start
   Goto Start
End

Event BotChat
   GetChatLine $a
   GetChatName $n
   Concat $b "I heard " $n " say: " $a   
   Say $b
   ChatImpair 3
EndEvent

In event handlers you must follow certain rules, due to the fact that they interrupt the execution of the script without changing its flow. In an event handler:



backIndex