Table of Contents
AI Scripting
The Ryzom Core AI system has a sophisticated custom scripting language that is used for scripting the various group states.
You can also get thorough documentation by going to
AI Scripting Native Functions Reference.
Table of Contents |
---|
Here's an example of a simple code block:
Code Block |
---|
(aggroSize)getAggorListSize(0); // to much player are attacking the boss if (aggoroSize > 10) { ($player1)getAggroListElement(0); ($player2)getAggroListElement(1); ($player3)getAggroListElement(2); // so the boss teleport 3 person from its aggro list at the end of the world teleportPlayer($player1, 14233, 123123, 0, 0); teleportPlayer($player2, 14233, 123123, 0, 0); teleportPlayer($player2, 14233, 123123, 0, 0); clearAggroList(); } |
In addition to code segments within AI actions you can also create AI script templates in World Editor using the script_rep and script nodes. It looks a little like this:
AI Script Rep Container in World Editor
AI Script Window for Script Rep
...
Debug and logThere are two special function for debug and logging:
- print: used for debug purpose, removed in release mode
- log: used to display any information that should be read in release mode
Syntax:
Code Block |
---|
print("foo"); log("bar"); |
Note | ||
---|---|---|
You can put any number of const string (e.g. "toto") and var ( Example:
|
About
functionsFunctionsYou can dynamically define function on the group.
This function are called script function or user function (as opposed to the hard coded
‘native function’‘native function’).
User functions don't have parameters.
Functions can be defined this way:
Code Block |
---|
my_function() { print("message"); // print a message mavar = 5*mavar; // the variable mavar is now equals to mavar*5 caller.mavar = mavar; // the variable mavar of the caller's is now equal to mavar (see info |
box for more explanation) } |
Info |
---|
In the above code we could replace caller by parent which is another keyword that indicate the parent of a machine state. The parent/children relation is defined for dynamic spawned groups (see AI Scripting Native Functions Reference). |
You can call a function like this (note that if a function is not defined for a group, nothing is called):
Code Block |
---|
my_function(); // call my_function from this group
group1_tryker.my_function(); // call my_function for group1_tryker (inside this function the current group is accessible via caller keyword) |
Variable manipulationSome simple mathematical operators can be used: +, -, /, * with or without parenthesis.
Example:
Code Block |
---|
mavar =(5*mavar+1)/3; |
Note that the negative operator should be used with caution, YOU MUST add a space after the ‘-‘ symbol.
You can do comparison with variables and or numbers (can be used for if and while statements).
Code Block |
---|
mavar = 10;
if(mavar < 10)
{
// ...
} |
Warning |
---|
You cannot do mathematical computation inside of an if statement. For example you cannot write: if (x+10 < 20)) |
Code flow structureClassical code flow constructswhile, if, else can be used as in C.
onchildrenonchildren special construct allow you to execute a script block on all the child of the current group.
while, if, else can be used as in C.
onchildrenonchildren special construct allow you to execute a script block on all the child of the current group.
Code Block |
---|
onchildren()
{
// ...
} |
onchildrenrandom special construct allow you to execute randomly a block of code among several. One instruction in the block following rand keyword is chosen and executed. This instruction can be a block, in which case the whole block is executed.
Code Block |
---|
random()
{
block1();
{ // Block2 begin
print("foo");
} // Block2 end
(bar)block3(baf);
} |
Native function callsNative calls are available too. Native calls offer hard coded services to the scripter.
Native calls have input and output parameters (AKA parameters and return values).
Code Block |
---|
(destVar1,destVar2)nativeMethod(ParamVar1); |
This line calls the function nativeMethod for the current group. The left parenthesis are used to define output arguments, the right for input arguments.