backIndex

Xelagot action script

Bot Client statements

Script statements are subject to change while the Server/Client is in beta testing

Version 2.9999949

Note: 'bot,master' protocol must be changed to 'master' as from version 2.9999949.

See Bot Clients and action script and Setting up a script connection for specific information about the Bot Client, and Events: Bot Client events for how to use the event handlers.

At the bottom of this page, there is code that shows how to establish simple communication between 2 bots.

Variables shown in black may be substituted by literal values, variables shown in red are assigned the result of the operation, variables in green may not be substituted by their literal equivalents.

Preparation. The Host or IP number and Port of the remote server, the Login name and, if required, Password, must be set by the script before attempting to open a connection to the remote server.

CLHost $h
sets the IP number or host address of the remote server.
CLPort %p
sets the port number of the remote server
CLLogin $n
sets the Login name to be used to log into the remote server.
CLPassword $w
sets the password, if one is required.
CLReconnect On
CLReconnect Off
Enables or disables automatic reconnection after an interruption. Note: as long as the client has not logged into a server, automatic reconnection does not work.
CLReconnectDelay %d
sets the delay in seconds between attempts to reconnect.
CLReconnectAttempts %d
sets number of times the client attempts to reconnect before pausing.
CLReconnectPause %d
sets the pause in seconds between batches of reconnect attempts.
CLReconnectCycles %d
sets the number of times the reconnect-attemps/pause cycle must be repeated. If set to -1, the cycle will always be repeated.

Once the data are set, the script must install the necessary event handlers. See Events: Bot Client handlers. After this, the Bot Client can attempt to connect. It can then exchange information with the remote server.

CLConnect
disconnects the Bot Client if it is connected to a remote server, attempts to connect to a remote server. Triggers events CLConnect, CLLogin and CLAdd. Always wait until the event CLLogin has been detected to send any messages to clients or to the remote server. If the loggin procedure succeeds, the Bot Client will remain connected to the remote server until it is disconnected by one of these causes:
  • connection fails
  • the script issues the CLDisconnect statement
  • the remote server disconnects the Bot Client or goes offline
  • program ends
If the script ends without disconnecting the Bot Client, it stays connected.
CLWrite $n $a
sending bot channel destination bot
sends a message to a BotClient on a server with CLWrite

message
receives in OnCLMessage

may receive a message in OnCLMessage event handler.

message
may send back a message using CLWrite
if the Bot Client is logged in, sends string $a to a comma separated list of Login names in $n that use the Bot protocol. If a literal string is sent ($a), it must be surrounded by "". String $a may contain any message. It will be received by the destination bot in its event CLMessage and must be parsed there.
CLWriteAll $a
if the Bot Client is logged in, sends string $a to all Login names in $n that use the Bot protocol. String $a may contain anything, like chatlines do. If a literal string is sent ($a), it must be surrounded by "". It will be received by the destination bot in its event CLMessage.
CLWriteToBot $n $a
Requires master protocol in the sending bot. If the Bot Client is logged in, sends string $a to a comma separated list of Login names in $n. If a literal string is sent ($a), it must be surrounded by "". String $a must contain a command in the same format as the WriteToBot commands. This command is executed inmediately by that bot. For most commands, the destination bot does not need to be running a script, but it must be connected to the same server as the sending bot. One command does require the destination bot to be running a script with a CLMessage event handler: Message. The Hear command may be trapped by a CLHear event handler.
AnyWriteToBot $n $a
Requires master protocol in the sending bot for sending messages to destination bots not in the same program. If the name in $n is a botname in the same program, this statement works as WriteToBot and sends string $a to the bot, which must trap it in a BotMessage event handler; otherwise, if the Bot Client is logged in, sends string $a to Login name in $n (not to a comma separated list of Login names). If a literal string is sent ($a), it must be surrounded by "". String $a must contain a command in the same format as the WriteToBot commands. This command is executed inmediately by that bot. For most commands, the destination bot does not need to be running a script, but it must be connected to the same server as the sending bot (or run in the same program). One command does require the destination bot to be running a script with a CLMessage event handler: Message. The Hear command may be trapped by a CLHear event handler.
CLDisconnect
disconnects from a remote server. Triggers event CLDisconnect.
CLListOnline
if the Bot Client is loged in, queries the BotClient's online list. Triggers events CLAdd. Not needed when connecting to the remote server: these events are triggerd automatically after the event CLLogin occurs.
IfCLIsOnline $n statement1
Else statement2
$n is a Login name. Executes statement1 if name $n appears on the BotClient's online list.
IfCLLoggedIn statement1
Else statement2
executes statement1 if the Bot Client is logged into the remote server, otherwise optionally statement2 is executed. Note that the test is "logged in", not "connected": if the Bot Client is connected but still logging in, the test will be negative and statement1 will not be executed. Statement IfCLIsOnline $n gives the same result as this statement if $n is the bot's Login name.


Example code

Preliminaries: there must be a bot server running, which already has the login data of the bots. Lets assume the server is running on IP 123.123.123.1, Port 45000, and that it allows bots to log in as 'Suzan', using the password 'got2go', and as 'Peter', password 'dontgo'. Suppose the bots are called Suzan and Peter. The following code will show you how to establish the connection, send and receive messages, and close the connection.

You can say to the bot the following:

[Head]
Type=Script
Version=2.0

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

[Script]
var $Host, %Port, $MyLogin, $MyPassword
var $Login, $chat, $Destination, $Message

  # insert the appropriate data for each bot here
  $Host = "123.123.123.1"
  %Port = 45000
  $MyLogin = "Suzan"
  $MyPassword = "got2go"
  
  OnChatEvent AvChat
  OnCLLoginEvent CLLogin
  OnCLDisconnectEvent CLDisconnect
  OnCLMessageEvent CLMessage

Label MainLoop
  Goto MainLoop
End


Event AvChat
  GetChatPerson &p
  IfPerson &p IsNotBoss EndEvent
  GetChatName $Login
  GetChatLine $chat
  IfString $chat = "connect" Gosub OpenConnection
  Else IfString $chat = "disconnect" Gosub CloseConnection
  Else IfString "send to " IsIn $chat Gosub Parse
  Else SayConcat "What?"
EndEvent

Sub Parse
  Split $a $b $chat "send to "
  # $a has the first part of chat, before "send to "
  # $b has the rest
  Split $Destination $Message $b ":"
  # now $Destination has the second bit before the ":"
  # $Message has the last bit
  IfString $Destination <> "" IfString $Message <> "" Gosub SendMessage
  Else SayConcat "Hmmm..."
EndSub

Event CLMessage
  GetEventLogin $Login
  GetMessage $chat
  SayConcat "Received message from " $Login ": " $chat
  # the next statement avoids looping...
  IfString $chat = "I hear you" EndEvent
  SayConcat "Sending message to " $Login ": I hear you"
  CLWrite $Login "I hear you"
EndEvent

Event CLLogin
  SayConcat "I logged into the server"
EndEvent

Event CLDisconnect
  SayConcat "I am disconnected from the server"
EndEvent

Sub SendMessage
  IfCLLoggedIn IfCLIsOnline $Destination CLWrite $Destination $Message
  Else IfCLLoggedIn SayConcat $Destination " is offline"
  Else SayConcat "I am not connected"
  # note: IfCLLoggedIn is for the bot itself
  # IfCLIsOnline is for $Destination
EndSub

Sub OpenConnection
  IfCLLoggedIn SayConcat "I am already connected to the server"
  IfCLLoggedIn EndSub
  CLHost $Host
  CLPort %Port
  CLLogin $MyLogin
  CLPassword $MyPassword
  CLConnect
EndSub

Sub CloseConnection
  IfCLLoggedIn CLDisconnect
  Else SayConcat "I was not connected to the server"
EndSub


backIndex