backIndex

Xelagot action script

Introduction

Scripts require some programming skills to write. This section is for persons who wish to have a go at scripting.

Scripts can be loaded on the fly, without having to unload the bot. All variables, labels, subs and statements are case insensitive.

Scripts can be made with any text processor in text mode. They can be loaded and started/stopped at the selector under menu Uni item Dialog, Scripts, box Action Script. They can also be loaded using a verbal command: /loadscript filename.

You can make a blank starting script by selecting New and Save. You will have to add manually the End statement.

STRUCTURAL ELEMENTS

The structural elements of a script are:

For example:

[Head]
Type=Script
Version=2.0

[Settings]
Origin=0.000n 0.000w 0.00a 0.0
Run   <-- optional

[Script]
#first the variable declarations
#then the main body of the script

End
#here the subs, event-handlers and text fields

The End statement is only required if the script has subs, event handlers or text fields. Indenting is optional. Comments can be added on their own line starting with #. Empty lines are allowed.

Statements in this script language are one-liners, (except for conditional statements). Operations on numbers, for instance, have to be split up into smaller units. E.g., to calculate this formula
x = a * Sin(y) + b * Cos(y)
you write, using 2 temporary variables %d and %e

In script Equivalent
Cos %d %y d = Cos(y) store the cosine of %y in %d
Mul %d %b %d d = b * d where, in the right hand side, d = Cos(y) has just been calculated, so this comes down to d = b * Cos(y) multiply %b by %d and store this value in %d
Sin %e %y e = Sin(y) store the sine of %y in %e
Mul %e %a %e e = a * e or e = b * Sin(y) multiply %a by %e and store this value in %e
Add %x %e %d x = e + d or x = a * Sin(y) + b * Cos(y) add %d and %e and store this value in %x

You can of course pack these formulas into a Sub:

[Head]
Type=Script
Version=2.0

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

[Script]
#first the variable declarations, excluding default variables
var %mysub_y, %mysub_x, %mysub_a, %mysub_b, %mysub_d, %mysub_e

#then the main body of the script
   
   #....
   %mysub_y = 30.78
   %mysub_a = 1.09
   %mysub_b = 60
   Gosub Mysub
   %x = %mysub_x
   #...
End
#here the subs

Sub Mysub
   #x = a * Sin(y) + b * Cos(y)
   Cos %mysub_e %mysub_y
   Mul %mysub_e %mysub_b %mysub_e
   Sin %mysub_d %mysub_y
   Mul %mysub_d %mysub_a %mysub_d
   Add %mysub_x %mysub_d %mysub_e   
Return
	

Subs, Events and Text fields are discussed elswhere. They, together with the Main block of the script, are the major structural elements. Labels are used to change the execution flow of the script, which is usually done using conditional statements.

Very simple scripts can be made without using Subs, Events or Text fields. But most scripts will have to include Event handlers: without them, the bot can not process chat or react to things happening in-world.

The following pages have an introduction on variables and discuss the various variable types and their operations. Next, the conditional statements (which you will have encountered when reading about the variables) are explained, followed by Labels, Subs and Text fields. I close the introductory part with a note on errors and debugging.

Then I discuss statements dealing with avatar, gesture, motion and talking.

The large group of pages on Events may frighten you a bit at first, but events are what drive the bot. You may only need, at first, to read the general page on events, and the first part of the one dealing with chat.

The last group of pages deal about what did not fit into the previous groups. The page called Examples has a set of full working scripts.

The pages are not in a didactic (learning) order: you may jump from page to page at will.


backIndex