Creation/Dev/GScript2: Difference between revisions

From Graal Bible
(the old file was outdated)
Line 1: Line 1:
GScript 2 is the new scripting engine for [[Graal]]
<pre>
1. Introduction
 
1.1. Why scripts
 
Scripts bring life into objects and make it easy to
customize the game. Instead of just placing a stone
into your world, you can make it so that the stone
can be lifted or kicked. Instead of being limited to
some fixed player movement you can rescript it
to let the player jump, strafe and duck. To let the
player inspect and organize his/her items you can
create some dialogs and display those by script,
e.g. when the player presses a special key.
 
In Graal the scripting is done in 'Graal Script',
it's looking like Java/C++, but brings some
additional features for making things easier
for game creators, while on the other hand
running in a sandbox and limiting access to
game-related stuff only.
 
Graal Script is almost fully compatible to
the 'old' Graal script used in Graal v1.0 - 3.0,
and is partially compatible to Torque script.
 
1.2. NPCs and 'weapons'
 
There are generally two types of objects in Graal
which have scripts: The first type are the
non-player-characters (NPCs). The name 'NPC' is
actually used for all visible objects in the game:
monsters, stones, bushes, houses, ships, plants etc.
Scripts for npcs are most of the time containing
code for moving the npc or for reacting to
activities of the player, e.g. giving money to
the player when he grabs the npc.
The other type of script-holding objects are the
'weapons'. Those are items in the inventory of
the player, not necessary being weapons. Most of
the time they are actually just scripts which
control the movement of the player, display weapon
graphics, or display menus.
 
So there are objects in the game which have
their own script, and players which have a set
of scripts in their invisible backpack.
 
1.3. Server-side and client-side
 
Graal is an online game, and there are differences
to standard scripting in offline games.
In offline programs you have access to everything,
anytime. In online games everything is divided
into two parts: the server-side which controls
most things in the game, and the client-side which
displays the game to the player.
Since the client only displays things, it is not
possible to cheat by hacking the client. On client-side
you mainly have code for displaying special effects,
for displaying the GUI (windows, status bars, item menus),
playing sound effects and music. Also the player
movement is done on client-side.
On the server-side scripts are used to do the more
secure parts of the game engine are implemented,
and things that are the same for all players -
npcs are added, moved, npcs interact with players,
the stats of the players are calculated, the
communication between players is handled.
 
All scripts for npcs and weapons can contain
server-side code and client-side code. The server-side
code is executed directly on the server, the
client-side code is sent to the client when he
logins and executed separately for each player on
their own computer. Usually the two parts of the script
are divided by line that only contains "//#CLIENTSIDE",
like this:
 
// Server-side part which is setting the image
// of the npc when it is created
function onCreated() {
  setimg("door.png");
}
 
//#CLIENTSIDE
 
// Here follows the client-side part,
// which plays a sound effect when the player
// touchs the npc
function onPlayerTouchsme() {
  play("chest.wav");
}
 


== Old Script Compatibility ==
1.4. Events


=== Removed functionality ===
In general scripts are made for reacting to
events - when the npc is created then the script
initializes the attributes of the npc,
when the player says something then the npc is
moving to the player, when the player grabs the
npc then the npc is giving the player some money etc.
So the script is basicly a collection of actions
that are done when special events are happening.
Events can e.g. be the "created" event when the npc
is created, the "playertouchsme" event when the
player touchs the npc, or the "playerchats" event
when the player says something. To write code reacts
to one of those event, you define an event
function like this:


<ul>
function onEVENTNAME() {
<li>toinventory
  // actions
<li>followplayer
}
<li>playersays()
<li>setbackpal
</ul>


=== Supported old scripting commands & their mapping to new script ===
When the event is happening, then Graal executes
that scripting function and all commands you
have added there.
Sometimes the event gives some parameters to the
event function, then change your function to:


<dl>
function onEVENTNAME(parameter1, paramater2, ...) {
<dt>addstring oldstring, oldstring;
  // actions
<dd>addstring(string,string);
}


<dt>addtiledef oldstring, oldstring, float;
By accessing 'parameter1' etc. (you can name
<dd>addtiledef(string,string,float);
them differently) you can react to the event more
exactly.


<dt>addtiledef2 oldstring, oldstring, float, float;
Instead of reacting to events, the npcs and
<dd>addtiledef2(string,string,float,float);
weapons can also invoke new events. That way
you can let other npcs doing things. You also
need that if you want to coninuously doing things -
use timeout event for that.


<dt>attachplayertoobj float, float;
function onCreated() {
<dd>attachplayertoobj(float,float);
  timeout = 1;
}


<dt>blockagain;
function onTimeout() {
<dd>                                blockagain();
  // actions
<dt>blockagainlocal;
  timeout = 1;
<dd>                                blockagainlocal();
}
<dt>callnpc float, oldstring;
<dd>                                callnpc(float,string);
<dt>callweapon float, oldstring;
<dd>                                callweapon(float,string);
<dt>canbecarried;
<dd>                                canbecarried();
<dt>canbepulled;
<dd>                                canbepulled();
<dt>canbepushed;
<dd>                                canbepushed();
<dt>cannotbecarried;
<dd>                                cannotbecarried();
<dt>cannotbepulled;
<dd>                                cannotbepulled();
<dt>cannotbepushed;
<dd>                                cannotbepushed();
<dt>canwarp;
<dd>                                canwarp();
<dt>canwarp2;
<dd>                                canwarp2();
<dt>carryobject oldstring;
<dd>                                carryobject(string);
<dt>changeimgcolors float, float, float, float, float;
<dd>                                changeimgcolors(float,float,float,float,float);
<dt>changeimgmode float, float;
<dd>                                changeimgmode(float,float);
<dt>changeimgpart float, float, float, float, float;
<dd>                                changeimgpart(float,float,float,float,float);
<dt>changeimgvis float, float;
<dd>                                changeimgvis(float,float);
<dt>changeimgzoom float, float;
<dd>                                changeimgzoom(float,float);
<dt>deletestring oldstring, float;
<dd>                                deletestring(string,float);
<dt>destroy;
<dd>                                destroy();
<dt>detachplayer;
<dd>                                detachplayer();
<dt>disabledefmovement;
<dd>                                disabledefmovement();
<dt>disablemap;
<dd>                                disablemap();
<dt>disablepause;
<dd>                                disablepause();
<dt>disableselectweapons;
<dd>                                disableselectweapons();
<dt>disableweapons;
<dd>                                disableweapons();
<dt>dontblock;
<dd>                                dontblock();
<dt>dontblocklocal;
<dd>                                dontblocklocal();
<dt>drawaslight;
<dd>                                drawaslight();
<dt>drawoverplayer;
<dd>                                drawoverplayer();
<dt>drawunderplayer;
<dd>                                drawunderplayer();
<dt>enabledefmovement;
<dd>                                enabledefmovement();
<dt>enablefeatures float;
<dd>                                enablefeatures(float);
<dt>enablemap;
<dd>                                enablemap();
<dt>enablepause;
<dd>                                enablepause();
<dt>enableselectweapons;
<dd>                                enableselectweapons();
<dt>enableweapons;
<dd>                                enableweapons();
<dt>explodebomb float;
<dd>                                explodebomb(float);
<dt>followplayer;
<dd>                                followplayer();
<dt>freezeplayer float;
<dd>                                freezeplayer(float);
<dt>freezeplayer2;
<dd>                                freezeplayer2();
<dt>hide;
<dd>                                hide();
<dt>hideimg float;
<dd>                                hideimg(float);
<dt>hideimgs float, float;
<dd>                                hideimgs(float,float);
<dt>hidelocal;
<dd>                                hidelocal();
<dd>
<dt>hitcompu float, float, float, float;
<dd>                                hitcompu(float,float,float,float);
<dt>hitnpc float, float, float, float;
<dd>                                hitnpc(float,float,float,float);
<dt>hitobjects float, float, float;
<dd>                                hitobjects(float,float,float);
<dt>hideplayer float;
<dd>                                hideplayer(float);
<dt>hidesword float;
<dd>                                hidesword(float);
<dt>hitplayer float, float, float, float;
<dd>                                hitplayer(float,float,float,float);
<dt>hurt float;
<dd>                                hurt(float);
<dt>insertstring oldstring, float, oldstring;
<dd>                                insertstring(string,float,string);
<dt>join oldstring;
<dd>                                join(string);
<dt>lay oldstring;
<dd>                                lay(string);
<dt>lay2 oldstring, float, float;
<dd>                                lay2(string,float,float);
<dt>loadmap oldstring;
<dd>                                loadmap(string);
<dt>message oldstring;
<dd>                                message(string);
<dt>move float, float, float, float;
<dd>                                move(float,float,float,float);
<dt>noplayerkilling;
<dd>                                noplayerkilling();
<dt>openurl oldstring;
<dd>                                openurl(string);
<dt>openurl2 oldstring, float, float;
<dd>                                openurl2(string,float,float);
<dt>play oldstring;
<dd>                                play(string);
<dt>play2 oldstring, float, float, float;
<dd>                                play2(string,float,float,float);
<dt>playlooped oldstring;
<dd>                                playlooped(string);
<dt>putbomb float, float, float;
<dd>                                putbomb(float,float,float);
<dt>putcomp oldstring, float, float;
<dd>                                putcomp(string,float,float);
<dt>putexplosion float, float, float;
<dd>                                putexplosion(float,float,float);
<dt>putexplosion2 float, float, float, float;
<dd>                                putexplosion2(float,float,float,float);
<dt>puthorse oldstring, float, float;
<dd>                                puthorse(string,float,float);
<dt>putleaps float, float, float;
<dd>                                putleaps(float,float,float);
<dt>putnewcomp oldstring, float, float, oldstring, float;
<dd>                                putnewcomp(string,float,float,string,float);
<dt>putnpc oldstring, oldstring, float, float;
<dd>                                putnpc(string,string,float,float);
<dt>putnpc2 float, float, oldstring;
<dd>                                putnpc2(float,float,string);
<dt>reflectarrow float;
<dd>                                reflectarrow(float);
<dt>removearrow float;
<dd>                                removearrow(float);
<dt>removebomb float;
<dd>                                removebomb(float);
<dt>removecompus;
<dd>                                removecompus();
<dt>removeexplo float;
<dd>                                removeexplo(float);
<dt>removehorse float;
<dd>                                removehorse(float);
<dt>removeitem float;
<dd>                                removeitem(float)
<dt>removestring oldstring, oldstring;
<dd>                                removestring(string,string);
<dt>removetiledefs oldstring;
<dd>                                removetiledefs(string);
<dt>replaceani oldstring, oldstring;
<dd>                                replaceani(string,string);
<dt>replacestring oldstring, float, oldstring;
<dd>                                replacestring(string,float,string);
<dt>resetfocus;
<dd>                                resetfocus();
<dt>savelog oldstring;
<dd>                                savelog(string);
<dt>savelog2 oldstring, oldstring;
<dd>                                savelog2(string,string);
<dt>say float;
<dd>                                say(float);
<dt>say2 oldstring;
<dd>                                say2(string);
<dt>sendrpgmessage oldstring;
<dd>                                sendrpgmessage(string);
<dt>sendpm oldstring;
<dd>                                sendpm(string);
<dt>sendtonc oldstring;
<dd>                                sendtonc(string);
<dt>sendtorc oldstring;
<dd>                                sendtorc(string);
<dt>serverwarp oldstring;
<dd>                                serverwarp(string);
<dt>set oldstring;
<dd>                                set(string);
<dt>setani oldstring, oldstring;
<dd>                                setani(string,string);
<dt>setarray float, float;
<dd>                                setarray(var,float);
<dt>setbeltcolor oldstring;
<dd>                                setbeltcolor(string);
<dt>setbow oldstring;
<dd>                                setbow(string);
<dt>setcharani oldstring, oldstring;
<dd>                                setcharani(string,string);
<dt>setchargender oldstring;
<dd>                                setchargender(string);
<dt>setcharprop oldstring, oldstring;
<dd>                                string = string;
<dt>setcoatcolor oldstring;
<dd>                                setcoatcolor(string);
<dt>setcoloreffect float, float, float, float;
<dd>                                setcoloreffect(float,float,float,float);
<dt>setcursor float;
<dd>                                setcursor(float);
<dt>setcurcor2 oldstring;
<dd>                                setcursor2(string);
<dt>seteffect float, float, float, float;
<dd>                                seteffect(float,float,float,float);
<dt>seteffectmode float;
<dd>                                seteffectmode(float);
<dt>setfocus float, float;
<dd>                                setfocus(float,float);
<dt>setgender oldstring;
<dd>                                setgender(string);
<dt>sethead oldstring;
<dd>                                sethead(string);
<dt>setlevel oldstring;
<dd>                                setlevel(string);
<dt>setlevel2 oldstring, float, float;
<dd>                                setlevel2(string,float,float);
<dt>setmap oldstring, oldstring, float, float;
<dd>                                setmap(string,string,float,float);
<dt>setminimap oldstring, oldstring, float, float;
<dd>                                setminimap(string,string,float,float);
<dt>setmusicvolume float, float;
<dd>                                setmusicvolume(float,float);
<dt>setimg oldstring;
<dd>                                setimg(string);
<dt>setimgpart oldstring, float, float, float, float;
<dd>                                setimgpart(string,float,float,float,float);
<dt>setletters oldstring;
<dd>                                setletters(string);
<dt>setplayerdir oldstring;
<dd>                                setplayerdir(string);
<dt>setplayerprop oldstring, oldstring;
<dd>                                string = string;
<dt>setpm oldstring;
<dd>                                setpm(string);
<dt>setshape float, float, float;
<dd>                                setshape(float,float,float);
<dt>setshape2 float, float, float;
<dd>                                setshape2(float,float,float);
<dt>setshield oldstring, float;
<dd>                                setshield(string,float);
<dt>setshoecolor oldstring;
<dd>                                setshoecolor(string);
<dt>setshootparams oldstring;
<dd>                                setshootparams(string);
<dt>setskincolor oldstring;
<dd>                                setskincolor(string);
<dt>setsleevecolor oldstring;
<dd>                                setsleevecolor(string);
<dt>setstring oldstring, oldstring;
<dd>                                setstring(string,string);
<dt>setsword oldstring, float;
<dd>                                setsword(string,float);
<dt>seturllevel oldstring;
<dd>                                seturllevel(string);
<dt>setz float, float, float, float, float, float, float, float;
<dd>                                setz(float,float,float,float,float,float,float,float);
<dt>setzoomeffect float;
<dd>                                setzoomeffect(float);
<dt>shoot float, float, float, float, float, float, oldstring, oldstring;
<dd>                                shoot(float,float,float,float,float,float,string,string);
<dt>shootarrow float;
<dd>                                shootarrow(float);
<dt>shootball;
<dd>                                shootball();
<dt>shootfireball float;
<dd>                                shootfireball(float);
<dt>shootfireblast float;
<dd>                                shootfireblast(float);
<dt>shootnuke float;
<dd>                                shootnuke(float);
<dt>show;
<dd>                                show();
<dt>showani float, float, float, float, oldstring;
<dd>                                showani(float,float,float,float,string);
<dt>showani2 float, float, float, float, float, oldstring;
<dd>                                showani2(float,float,float,float,float,string);
<dt>showcharacter;
<dd>                                showcharacter();
<dt>showfile oldstring;
<dd>                                showfile(string);
<dt>showimg float, oldstring, float, float;
<dd>                                showimg(float,string,float,float);
<dt>showimg2 float, oldstring, float, float, float;
<dd>                                showimg2(float,string,float,float,float);
<dt>showlocal;
<dd>                                showlocal();
<dt>showpoly float, float;
<dd>                                showpoly(float,array);
<dt>showpoly2 float, float;
<dd>                                showpoly2(float,array);
<dt>showstats float;
<dd>                                showstats(float);
<dt>showtext float, float, float, oldstring, oldstring, oldstring;
<dd>                                showtext(float,float,float,string,string,string);
<dt>showtext2 float, float, float, float, oldstring, oldstring, oldstring;
<dd>                                showtext2(float,float,float,float,string,string,string);
<dt>sleep float;
<dd>                                sleep(float);
<dt>spyfire float, float;
<dd>                                spyfire(float,float);
<dt>stopmidi;
<dd>                                stopmidi();
<dt>stopsound oldstring;
<dd>                                stopsound(string);
<dt>take oldstring;
<dd>                                take(string);
<dt>take2 float;
<dd>                                take2(float);
<dt>takehorse float;
<dd>                                takehorse(float);
<dt>takeplayercarry;
<dd>                                takeplayercarry();
<dt>takeplayerhorse;
<dd>                                takeplayerhorse();
<dt>throwcarry;
<dd>                                throwcarry();
<dt>timereverywhere;
<dd>                                timereverywhere();
<dt>timershow;
<dd>                                timershow();
<dt>toinventory oldstring;
<dd>                                toinventory(string);
<dt>tokenize oldstring;
<dd>                                tokens = string.tokenize();
<dt>tokenize2 oldstring, oldstring;
<dd>                                tokens = string.tokenize(" ," @ string);
<dt>toweapons oldstring;
<dd>                                toweapons(string);
<dt>triggeraction float, float, oldstring, oldstring;
<dd>                                triggeraction(float,float,string,string);
<dt>unfreezeplayer;
<dd>                                unfreezeplayer();
<dt>unset oldstring;
<dd>                                unset(string);
<dt>updateboard float, float, float, float;
<dd>                                updateboard(float,float,float,float);
<dt>updateterrain;
<dd>                                updateterrain();
<dt>wraptext float, oldstring, oldstring;
<dd>                                tokens = wraptext(float," ," @ string,string);
<dt>wraptext2 float, float, oldstring, oldstring;
<dd>                                tokens = wraptext2(float,float," ," @ string,string);
</dl>


=== Supported old string operations ===
In the onCreated event function the script is
setting the timer to 1 second. When that second is
over, then the "timeout" event is invoked on the
npc and the onTimeout event function is executed.
Because it is setting the timeout to 1 second
again, the onTimeout even will occur again after
one second, and so on.


These old string operators can be used in string parameters for the old commands, also you can use them directly as operators, e.g.<br/>
<pre>#c = "hello"</pre>
is actually doing<br/>
<pre>player.chat = "hello"</pre>


<pre>
#a            player.account
#a(float)    players[float].account
#m            player.ani
              ani
#m(float)    players[float].ani
#K(float)    ascii(float)
#8            player.bodyimg
              bodyimg
#8(float)    players[float].bodyimg
#c            player.chat
              chat
#c(float)    players[float].chat
#C0          player.colors[0]
              colors[0]
#C0(float)    players[float].colors[0]
#C1          player.colors[1]
              colors[1]
#C1(float)    players[float].colors[1]
#C2          player.colors[2]
              colors[2]
#C2(float)    players[float].colors[2]
#C3          player.colors[3]
              colors[3]
#C3(float)    players[float].colors[3]
#C4          player.colors[4]
              colors[4]
#C4(float)    players[float].colors[4]
#C5          player.colors[5]
              colors[5]
#C5(float)    players[float].colors[5]
#D            downloadfile()
#E            emoticonchar()
#e(float,float,oldstring)
              string.substring(float,float)
#g            player.guild
              guild
#g(float)    players[float].guild
#3            player.headimg
              headimg
#3(float)    players[float].headimg
#5            player.horseimg
              horseimg
#5(float)    players[float].horseimg
#k(float)    keyname(float)
#L            player.level
#I(oldstring,float)
              getstring(string)[float]
#n            player.nick
              nick
#n(float)    players[float].nick
#f            image
#f(float)    npcs[float].image
#F            level
#p(float)    params[float]
#P(float)    player.attr[float]
              attr[float]
#P(float,float)
              players[float].attr[float]
#P1          player.attr[1]
              attr[1]
#P1(float)    players[float].attr[1]
#P2          player.attr[2]
              attr[2]
#P2(float)    players[float].attr[2]
#P3          player.attr[3]
              attr[3]
#P3(float)    players[float].attr[3]
#P4          player.attr[4]
              attr[4]
#P4(float)    players[float].attr[4]
#P5          player.attr[5]
              attr[5]
#P5(float)    players[float].attr[5]
#P6          player.attr[6]
              attr[6]
#P6(float)    players[float].attr[6]
#P7          player.attr[7]
              attr[7]
#P7(float)    players[float].attr[7]
#P8          player.attr[8]
              attr[8]
#P8(float)    players[float].attr[8]
#P9          player.attr[9]
              attr[9]
#P9(float)    players[float].attr[9]
#R(oldstring) string.random()
#2            player.shieldimg
              shieldimg
#2(float)    players[float].shieldimg
#s(oldstring) getstring(string)
#1            player.swordimg
              swordimg
#1(float)    players[float].swordimg
#S            player.sword.script
#t(float)    tokens[float]
#T(oldstring) string.trim()
#v(float)    float
#W            player.weapon.icon
#W(float)    weapons[float].icon
#w            player.weapon.script
#w(float)    weapons[float].script
</pre>


Compatibility note:
Compatibility note:
When you use the command setcharprop then the first parameter
In older Graal scripts you will also find the
is handled differently: instead of changing 'player.chat' it
deprecated way of receiving events:
is changing 'chat', the chat text of the npc. So 'setcharprop #c,hello'
 
would be translated into
if (EVENTNAME) {
chat = "hello"
  // actions
while 'setplayerprop #c,hello' is translated into
}
player.chat = "hello"
 
In the list above both possibilities are listed.
That is an if-command outside of any brackets. If
Graal sees that you use such an if-command, then
it will execute the whole script so that the actions
you have written inside the if-command will be
executed too.
 
 
2. Basics
 
2.1. Accessing variables
 
Graal Script variables are 'variant', that means they are objects
that hold values of different types.
When you assign a value to the variable then it automatically
switches to the right type:
 
Numeric (floating point):
  var = 1;
String:
  var = "hello";
Object link:
  var = player;
Array (list of objects):
  var = {1,2,3};
 
You can check the current type with the
type()-function - obj.type() returns
0,1,2,3 for numeric, string, object or array.


== Old Script Compatibility ==
2.2. Operators


=== Operators ===
<pre>
Addition                  a + b
Addition                  a + b
Substraction              a - b
Substraction              a - b
Line 528: Line 212:
In-Range                  a in <b,c>, a in |b,c>, a in <b,c|, a in |b,c|
In-Range                  a in <b,c>, a in |b,c>, a in <b,c|, a in |b,c|
In-Array                  a in {b,c,...}, {a,b,...} in {c,d,...}
In-Array                  a in {b,c,...}, {a,b,...} in {c,d,...}
Bitwise-Or                a | b
Bitwise-And              a & b
Bitwise-Shift left        a << b
Bitwise-Shift right      a >> b
Bitwise-Invert            ~a
Bitwise-Xor              a xor b (operator ^ already used for power)
Array-Constructor        {a,b,...}
Array-Constructor        {a,b,...}
Empty Array              new [count]
Empty Array              new [count]
Line 546: Line 236:
Modulus Assignment        a %= b
Modulus Assignment        a %= b
Power Assignment          a ^= b
Power Assignment          a ^= b
Bitwise-Or Assignment    a |= b
Bitwise-And Assignment    a &= b
Shift Left Assignment    a <<= b
Shift Right Assignment    a >>= b
String Append            a @= b
String Append            a @= b
</pre>


=== Accessing Variables ===
2.3. Standard object functions
 
Graal Script variables are 'variant', that means they are objects
that hold values of different types.
When you assign a value to the variable then it automatically
switches to the right type:
 
Numeric (floating point):
  var = 1;
String:
  var = "hello";
Object link:
  var = player;
Array (list of objects):
  var = {1,2,3};


You can check the current type with the
For a complete list of functions and attributes of objects
type()-function - obj.type() returns
see docu_graalscriptfunctions.txt. The base type of all
0,1,2,3 for numeric, string, object or array.
objects is "TGraalVar". You can also get the latest list by
calling the executale with "-listscriptfunctions" as
command-line parameter.  
Here only of the built-in functions:


=== Standard Object Functions ===
<pre>
obj.name
obj.type()  - gets the type of the var (float 0, string 1, object 2, array 3)
obj.type()  - gets the type of the var (float 0, string 1, object 2, array 3)
obj.length() - string length
obj.length() - string length
Line 578: Line 257:
obj.charat(pos)
obj.charat(pos)
obj.pos(substring)
obj.pos(substring)
obj.begins(string)
obj.starts(string)
obj.endson(string)
obj.ends(string)
obj.substring(index[,length])
obj.substring(index[,length])
obj.size() - array length
obj.size() - array length
obj.subarray(index[,length])
obj.addarray(obj2)
obj.insertarray(index,obj2)
obj.index(obj2) - position of obj2 in the array
obj.index(obj2) - position of obj2 in the array
obj.clear()
obj.clear()
Line 589: Line 271:
obj.replace(index,obj2)
obj.replace(index,obj2)
obj.insert(index,obj2)
obj.insert(index,obj2)
obj.getvarnames() - list of the object attributes
obj.geteditvarnames()
obj.loadstring(filename)
obj.loadlines(filename)
obj.loadvars(filename)
obj.savestring(filename,mode)
obj.savelines(filename,mode)
obj.savevars(filename,mode)
</pre>
==== NPCs ====
<pre>
npc.actionplayer - integer, read only
npc.ani - object, read only
npc.anistep - integer, read only
npc.ap - integer
npc.attr - array
npc.attached - boolean, read only
npc.attachid - integer, read only
npc.attachtype - integer, read only
npc.body - object
npc.bodyimg - string
npc.bombs - integer
npc.chat - string
npc.colors - array
npc.darts - integer
npc.dir - integer
npc.glovepower - integer
npc.gralats - integer
npc.head - object
npc.headimg - string
npc.headset - integer
npc.hearts - floating point value, better use npc.hp
npc.height - floating point value, read only
npc.horseimg - string
npc.hp - floating point value
npc.hurtdx - floating point value
npc.hurtdy - floating point value
npc.id - integer, read only
npc.isfemale - boolean, read only
npc.ismale - boolean, read only
npc.isweapon - boolean, read only
npc.layer - integer
npc.mp - integer
npc.nick - string
npc.peltwithnpc - boolean, read only
npc.peltwithbush - boolean, read only
npc.peltwithsign - boolean, read only
npc.peltwithvase - boolean, read only
npc.peltwithstone - boolean, read only
npc.peltwithblackstone - boolean, read only
npc.rupees - integer, better use npc.gralats
npc.shield - object
npc.shieldimg - string
npc.shieldpower - integer
npc.sprite - integer
npc.sword - object
npc.swordimg - string
npc.swordpower - integer
npc.timeout - floating point value
npc.visible - boolean
npc.width - floating point value, read only
npc.x - floating point value
npc.y - floating point value
npc.z - floating point value
npc.blockagain()
npc.blockagainlocal()
npc.canbecarried()
npc.cannotbecarried()
npc.canbepushed()
npc.cannotbepushed()
npc.canbepulled()
npc.cannotbepulled()
npc.carryobject(name)
npc.catchevent(object name,event,function)
npc.changeimgcolors(index,red,green,blue,alpha)
npc.changeimgmode(index,mode)
npc.changeimgpart(index,x,y,width,height)
npc.changeimgvis(index,layer)
npc.changeimgzoom(index,zoom factor)
npc.destroy()
npc.dontblock()
npc.dontblocklocal()
npc.drawaslight()
npc.drawoverplayer()
npc.drawunderplayer()
npc.getimageforsprite(sprite) - returns image
npc.getsprite(string) - returns sprite
npc.getspriteforspritepos(spritepos) - returns sprite
npc.hide()
npc.hidelocal()
npc.hideimg(index)
npc.hideimgs(startindex,endindex)
npc.hurt(power)
npc.ignoreevent(object name,event)
npc.ignoreevents(object name)
npc.lay(item name)
npc.message(text)
npc.move(delta x,delta y,time,options)
npc.setbow(image name)
npc.setcharani(ani name,parameters)
npc.setchargender("male" or "female")
npc.setcoloreffect(red,green,blue,alpha)
npc.seteffectmode(mode)
npc.setimg(image name)
npc.setimgpart(image name,x,y,width,height)
npc.setshape(type,pixelwidth,pixelheight)
npc.setshape2(tilewidth,tileheight,tilearray)
npc.setzoomeffect(zoom factor)
npc.shootarrow(direction)
npc.shootball()
npc.shootfireball(direction)
npc.shootfireblast(direction)
npc.shootnuke(direction)
npc.show()
npc.showani(index,x,y,direction,ani name,parameters)
npc.showani2(index,x,y,z,direction,ani name,parameters)
npc.showcharacter()
npc.showimg(index,image name,x,y)
npc.showimg2(index,image name,x,y,z)
npc.showlocal()
npc.showpoly(index,array)
npc.showpoly2(index,array)
npc.showtext(index,x,y,font,style,text)
npc.showtext2(index,x,y,z,font,style,text)
npc.take(item name)
npc.take2(item index)
npc.takehorse(horse index)
npc.throwcarry()
npc.timereverywhere()
npc.timershow()
npc.toweapons(weapon name)
</pre>
==== Players ====
<pre>
player.account - string, read only
player.ani - object, read only
player.anistep - integer, read only
player.ap - integer
player.attached - boolean, read only
player.attachid - integer, read only
player.attachtype - integer, read only
player.attr - array
player.body - object
player.bodyimg - string
player.bombs - integer
player.chat - string
player.colors - array
player.darts - integer
player.dir - integer
player.freezetime - floating point value, only valid for local players
player.fullhearts - integer, read only, better use player.maxhp
player.glovepower - integer
player.gralats - integer
player.head - object
player.headimg - string
player.headset - integer
player.hearts - floating point value, only editable for local players, better use player.hp
player.horseimg - string, only editable for local players
player.hp - floating point value, only editable for local players
player.hurt - boolean, read only, only valid for local players
player.hurtdx - floating point value, read only, only valid for local players
player.hurtdy - floating point value, read only, only valid for local players
player.hurted - boolean, read only, only valid for local players, better use player.hurt
player.hurtpower - floating point value, read only, only valid for local players
player.id - integer, read only
player.isfemale - boolean, read only
player.ismale - boolean, read only
player.letters - object, only valid for local players
player.level - object, read only
player.map - boolean, only valid for local players
player.maxhp - integer, read only
player.mp - integer
player.nick - string, read only for local players
player.onhorse - boolean, read only, only valid for local players
player.online - boolean, read only, only valid for local players
player.paused - boolean, read only, only valid for local players
player.reading - boolean, read only, only valid for local players
player.rupees - integer, better use player.gralats
player.shield - object
player.shieldimg - string
player.shieldpower - integer, read only
player.sprite - integer
player.swimming - boolean, read only, only valid for local players
player.sword - object
player.swordimg - string
player.swordpower - integer, read only
player.weapon - object, read only, only valid for local players
player.weapons - array, read only, only valid for local players
player.x - floating point value
player.y - floating point value
player.z - floating point value
player.getimageforsprite(sprite) - returns object
player.getsprite(string) - returns object
player.getspriteforspritepos(spritepos) - returns object
</pre>
==== Levels ====
==== Ganis ====
<pre>
e.g. player.ani
ani.name
ani.sprites[]
ani.steps[]
ani.continuous
ani.singledirection
ani.looping
ani.ismovie
ani.setbackto
ani.ganitype
ani.getsprite(id)
ani.addsprite(id) returns the added sprite
ani.deletesprite(id)
ani.addstep()
ani.insertstep(index)
ani.deletestep(index)
sprites:
sprite.spriteindex
sprite.image
sprite.imagetype
sprite.x
sprite.y
sprite.width
sprite.height
sprite.red
sprite.green
sprite.blue
sprite.alpha
sprite.zoom
sprite.mode
sprite.surface
sprite.attachments[]
sprite.addattachment()
sprite.insertattachment(index)
sprite.deleteattachment(index)
attachment:
attachment.sprite
attachment.dx
attachment.dy
attachment.behind
step:
step.spritespos[][]
step.sounds[]
step.delay
step.addpos(dir)
step.insertpos(dir,index)
step.deletepos(dir,index)
spritepos:
spritepos.sprite
spritepos.param
spritepos.attr
spritepos.dx
spritepos.dy
sound:
sound.sound
sound.dx
sound.dy
sound.delay


also the gani owners (players, npcs) have those functions:
2.4. Standard functions
getimageforsprite(sprite)
getsprite(string)
getspriteforspritepos(spritepos)
</pre>


=== Standard functions ===
<pre>
format(format,parameters,...) - formats a "%s %d" string, inserts the parameters, and returns a string
format(format,parameters,...) - formats a "%s %d" string, inserts the parameters, and returns a string
int(a)
int(a)
Line 878: Line 289:
vecx(direction)
vecx(direction)
vecy(direction)
vecy(direction)
</pre>


=== Standard variables ===
3. Events


== GUI ==
3.1. Gui controls


=== GUI controls ===
=== GUI events ===
<pre>
All controls:
onAdd() when added to the parent
onAdd() when added to the parent
onRemove() when removed from the parent
onRemove() when removed from the parent
Line 910: Line 315:
onKeyRepeat(keycode,string)
onKeyRepeat(keycode,string)


GuiMLTextCtrl:
3.1.1. GuiMLTextCtrl:
onResize(w,h) when reflowing
 
onReflow(w,h) when the text has changed
onURL(url) when clicked on url
onURL(url) when clicked on url
onSelectTag(tagid) when clicked on an image
Text-Tags:
The text of multi-line text controls can contain
a few HTML-tags and Torque-tags, you can use both
of those tag types to define colors and fonts
or to include images. Currently following tags
are available:
HTML:
<a href=url> text </a> - when the user clicks on 'text' then
  a web browser is opened for the specified url
<br> - line break
<font face=fontname size=textsize color=colorname or #rrggbb> text </font>
  - draws text with a special font, size and color; you only
  need to define one of those 3 attributes
<ignorelinebreaks> </ignorelinebreaks> - go into normal HTML mode where
  you need to insert <br> to do a linebreak
<img src=filename id=integer> - an image is displayed, you
  can also specify a tagid if you want to get onSelectTag-events
  for this image
<p align=left/center/right> - sets the align of the following text
<span style="width=100; height=100;" id=integer> </span> - for
  displaying a subpage, you can also specifiy an id for
  onSelectTag-events; instead of <span> you can also use <div> tags
Torque:
<a:url> text </a> - when the user clicks on 'text' then
  a web browser is opened for the specified url
<bitmap:filename> - an image is displayed
<color:rrggbb> - sets the color of the text (hexadecimal value)
<lmargin:pixels> - sets the left margin for the text
<lmargin%:percent> - sets the size of the left margin depending
  on the width of the whole control
<linkcolor:rrggbb> - sets the color of links (the <a>-tag)
<linkcolorhl:rrggbb> - sets the highlighted color, when
  the user moves the mouse over a link
<just:left/center/right> - sets the align of the following text
<rmargin:pixels> - sets the right margin for the text
<rmargin%:percent> - sets the size of the right margin depending
  on the width of the whole control
<sbreak> - line break
<spush> - switches to a new style (like <font>)
<spop> - switches back to the last saved style (like </font>)
<tab:tab1,tab2,..> - sets the position of where tabulators should
  be displayed if you have text like 'Apple \t Egg \t Chicken'
<tag:id> - inserts an invisible tag which can be used
  for the scrollToTag(id) function (beside image-tags)
3.1.2. GuiTextEditCtrl:


GuiTextEditCtrl:
onTabComplete()
onTabComplete()
onAction(text) when return key pressed
onAction(text) when return key pressed


GuiTextListCtrl:
3.1.3. GuiTextListCtrl:
 
onSelect(id,text) when row selected
onSelect(id,text) when row selected
onDblClick(id) when double-click on row or return key pressed
onDblClick(id) when double-click on row or return key pressed
Line 925: Line 382:
onOpenMenu(0,index,text) when an item was right-clicked
onOpenMenu(0,index,text) when an item was right-clicked


GuiPopUpMenuCtrl:
3.1.4. GuiPopUpMenuCtrl:
 
onSelect(id,text) when menu option choosen
onSelect(id,text) when menu option choosen
onCancel() when menu is closed without action
onCancel() when menu is closed without action
onOpenMenu(0,index,text) when an item was right-clicked
onOpenMenu(0,index,text) when an item was right-clicked


GuiMenuBar:
3.1.5. GuiMenuBar:
 
onMenuSelect(menuid,menutext)
onMenuSelect(menuid,menutext)
onMenuItemSelect(menuid,menutext,itemid,itemtext)
onMenuItemSelect(menuid,menutext,itemid,itemtext)


GuiTreeViewCtrl:
3.1.6. GuiTreeViewCtrl:
 
onSelect(id,rightmouse) when row selected
onSelect(id,rightmouse) when row selected
onUnselect(id) when row de-selected
onUnselect(id) when row de-selected
Line 940: Line 400:
onOpenMenu(0,index,text) when an item was right-clicked
onOpenMenu(0,index,text) when an item was right-clicked
onContextMenu("x y",id) when clicked with right-mouse key on row
onContextMenu("x y",id) when clicked with right-mouse key on row
4. Old script compatibility
4.1. Removed functionality
- toinventory
- followplayer
- playersays()
- setbackpal
4.2. Supported old scripting commands & their mapping to new script
addstring oldstring, oldstring;
                                addstring(string,string);
addtiledef oldstring, oldstring, float;
                                addtiledef(string,string,float);
addtiledef2 oldstring, oldstring, float, float;
                                addtiledef2(string,string,float,float);
attachplayertoobj float, float;
                                attachplayertoobj(float,float);
blockagain;
                                blockagain();
blockagainlocal;
                                blockagainlocal();
callnpc float, oldstring;
                                callnpc(float,string);
callweapon float, oldstring;
                                callweapon(float,string);
canbecarried;
                                canbecarried();
canbepulled;
                                canbepulled();
canbepushed;
                                canbepushed();
cannotbecarried;
                                cannotbecarried();
cannotbepulled;
                                cannotbepulled();
cannotbepushed;
                                cannotbepushed();
canwarp;
                                canwarp();
canwarp2;
                                canwarp2();
carryobject oldstring;
                                carryobject(string);
changeimgcolors float, float, float, float, float;
                                changeimgcolors(float,float,float,float,float);
changeimgmode float, float;
                                changeimgmode(float,float);
changeimgpart float, float, float, float, float;
                                changeimgpart(float,float,float,float,float);
changeimgvis float, float;
                                changeimgvis(float,float);
changeimgzoom float, float;
                                changeimgzoom(float,float);
deletestring oldstring, float;
                                deletestring(string,float);
destroy;
                                destroy();
detachplayer;
                                detachplayer();
disabledefmovement;
                                disabledefmovement();
disablemap;
                                disablemap();
disablepause;
                                disablepause();
disableselectweapons;
                                disableselectweapons();
disableweapons;
                                disableweapons();
dontblock;
                                dontblock();
dontblocklocal;
                                dontblocklocal();
drawaslight;
                                drawaslight();
drawoverplayer;
                                drawoverplayer();
drawunderplayer;
                                drawunderplayer();
enabledefmovement;
                                enabledefmovement();
enablefeatures float;
                                enablefeatures(float);
enablemap;
                                enablemap();
enablepause;
                                enablepause();
enableselectweapons;
                                enableselectweapons();
enableweapons;
                                enableweapons();
explodebomb float;
                                explodebomb(float);
followplayer;
                                followplayer();
freezeplayer float;
                                freezeplayer(float);
freezeplayer2;
                                freezeplayer2();
hide;
                                hide();
hideimg float;
                                hideimg(float);
hideimgs float, float;
                                hideimgs(float,float);
hidelocal;
                                hidelocal();
hitcompu float, float, float, float;
                                hitcompu(float,float,float,float);
hitnpc float, float, float, float;
                                hitnpc(float,float,float,float);
hitobjects float, float, float;
                                hitobjects(float,float,float);
hideplayer float;
                                hideplayer(float);
hidesword float;
                                hidesword(float);
hitplayer float, float, float, float;
                                hitplayer(float,float,float,float);
hurt float;
                                hurt(float);
insertstring oldstring, float, oldstring;
                                insertstring(string,float,string);
join oldstring;
                                join(string);
lay oldstring;
                                lay(string);
lay2 oldstring, float, float;
                                lay2(string,float,float);
loadmap oldstring;
                                loadmap(string);
message oldstring;
                                message(string);
move float, float, float, float;
                                move(float,float,float,float);
noplayerkilling;
                                noplayerkilling();
openurl oldstring;
                                openurl(string);
openurl2 oldstring, float, float;
                                openurl2(string,float,float);
play oldstring;
                                play(string);
play2 oldstring, float, float, float;
                                play2(string,float,float,float);
playlooped oldstring;
                                playlooped(string);
putbomb float, float, float;
                                putbomb(float,float,float);
putcomp oldstring, float, float;
                                putcomp(string,float,float);
putexplosion float, float, float;
                                putexplosion(float,float,float);
putexplosion2 float, float, float, float;
                                putexplosion2(float,float,float,float);
puthorse oldstring, float, float;
                                puthorse(string,float,float);
putleaps float, float, float;
                                putleaps(float,float,float);
putnewcomp oldstring, float, float, oldstring, float;
                                putnewcomp(string,float,float,string,float);
putnpc oldstring, oldstring, float, float;
                                putnpc(string,string,float,float);
putnpc2 float, float, oldstring;
                                putnpc2(float,float,string);
reflectarrow float;
                                reflectarrow(float);
removearrow float;
                                removearrow(float);
removebomb float;
                                removebomb(float);
removecompus;
                                removecompus();
removeexplo float;
                                removeexplo(float);
removehorse float;
                                removehorse(float);
rmeoveitem float;
                                removeitem(float)
removestring oldstring, oldstring;
                                removestring(string,string);
removetiledefs oldstring;
                                removetiledefs(string);
replaceani oldstring, oldstring;
                                replaceani(string,string);
replacestring oldstring, float, oldstring;
                                replacestring(string,float,string);
resetfocus;
                                resetfocus();
savelog oldstring;
                                savelog(string);
savelog2 oldstring, oldstring;
                                savelog2(string,string);
say float;
                                say(float);
say2 oldstring;
                                say2(string);
sendrpgmessage oldstring;
                                sendrpgmessage(string);
sendpm oldstring;
                                sendpm(string);
sendtonc oldstring;
                                sendtonc(string);
sendtorc oldstring;
                                sendtorc(string);
serverwarp oldstring;
                                serverwarp(string);
set oldstring;
                                set(string);
setani oldstring, oldstring;
                                setani(string,string);
setarray float, float;
                                setarray(var,float);
setbeltcolor oldstring;
                                setbeltcolor(string);
setbow oldstring;
                                setbow(string);
setcharani oldstring, oldstring;
                                setcharani(string,string);
setchargender oldstring;
                                setchargender(string);
setcharprop oldstring, oldstring;
                                string = string;
setcoatcolor oldstring;
                                setcoatcolor(string);
setcoloreffect float, float, float, float;
                                setcoloreffect(float,float,float,float);
setcursor float;
                                setcursor(float);
setcurcor2 oldstring;
                                setcursor2(string);
seteffect float, float, float, float;
                                seteffect(float,float,float,float);
seteffectmode float;
                                seteffectmode(float);
setfocus float, float;
                                setfocus(float,float);
setgender oldstring;
                                setgender(string);
sethead oldstring;
                                sethead(string);
setlevel oldstring;
                                setlevel(string);
setlevel2 oldstring, float, float;
                                setlevel2(string,float,float);
setmap oldstring, oldstring, float, float;
                                setmap(string,string,float,float);
setminimap oldstring, oldstring, float, float;
                                setminimap(string,string,float,float);
setmusicvolume float, float;
                                setmusicvolume(float,float);
setimg oldstring;
                                setimg(string);
setimgpart oldstring, float, float, float, float;
                                setimgpart(string,float,float,float,float);
setletters oldstring;
                                setletters(string);
setplayerdir oldstring;
                                setplayerdir(string);
setplayerprop oldstring, oldstring;
                                string = string;
setpm oldstring;
                                setpm(string);
setshape float, float, float;
                                setshape(float,float,float);
setshape2 float, float, float;
                                setshape2(float,float,float);
setshield oldstring, float;
                                setshield(string,float);
setshoecolor oldstring;
                                setshoecolor(string);
setshootparams oldstring;
                                setshootparams(string);
setskincolor oldstring;
                                setskincolor(string);
setsleevecolor oldstring;
                                setsleevecolor(string);
setstring oldstring, oldstring;
                                setstring(string,string);
setsword oldstring, float;
                                setsword(string,float);
seturllevel oldstring;
                                seturllevel(string);
setz float, float, float, float, float, float, float, float;
                                setz(float,float,float,float,float,float,float,float);
setzoomeffect float;
                                setzoomeffect(float);
shoot float, float, float, float, float, float, oldstring, oldstring;
                                shoot(float,float,float,float,float,float,string,string);
shootarrow float;
                                shootarrow(float);
shootball;
                                shootball();
shootfireball float;
                                shootfireball(float);
shootfireblast float;
                                shootfireblast(float);
shootnuke float;
                                shootnuke(float);
show;
                                show();
showani float, float, float, float, oldstring;
                                showani(float,float,float,float,string);
showani2 float, float, float, float, float, oldstring;
                                showani2(float,float,float,float,float,string);
showcharacter;
                                showcharacter();
showfile oldstring;
                                showfile(string);
showimg float, oldstring, float, float;
                                showimg(float,string,float,float);
showimg2 float, oldstring, float, float, float;
                                showimg2(float,string,float,float,float);
showlocal;
                                showlocal();
showpoly float, float;
                                showpoly(float,array);
showpoly2 float, float;
                                showpoly2(float,array);
showstats float;
                                showstats(float);
showtext float, float, float, oldstring, oldstring, oldstring;
                                showtext(float,float,float,string,string,string);
showtext2 float, float, float, float, oldstring, oldstring, oldstring;
                                showtext2(float,float,float,float,string,string,string);
sleep float;
                                sleep(float);
spyfire float, float;
                                spyfire(float,float);
stopmidi;
                                stopmidi();
stopsound oldstring;
                                stopsound(string);
take oldstring;
                                take(string);
take2 float;
                                take2(float);
takehorse float;
                                takehorse(float);
takeplayercarry;
                                takeplayercarry();
takeplayerhorse;
                                takeplayerhorse();
throwcarry;
                                throwcarry();
timereverywhere;
                                timereverywhere();
timershow;
                                timershow();
toinventory oldstring;
                                toinventory(string);
tokenize oldstring;
                                tokens = string.tokenize();
tokenize2 oldstring, oldstring;
                                tokens = string.tokenize(" ," @ string);
toweapons oldstring;
                                toweapons(string);
triggeraction float, float, oldstring, oldstring;
                                triggeraction(float,float,string,string);
unfreezeplayer;
                                unfreezeplayer();
unset oldstring;
                                unset(string);
updateboard float, float, float, float;
                                updateboard(float,float,float,float);
updateterrain;
                                updateterrain();
wraptext float, oldstring, oldstring;
                                tokens = wraptext(float," ," @ string,string);
wraptext2 float, float, oldstring, oldstring;
                                tokens = wraptext2(float,float," ," @ string,string);
4.3. Supported old scripting functions & their mapping to new script
4.4. Supported old string operations
These old string operators can be used in string parameters
for the old commands, also you can use them directly as operators, e.g.
#c = "hello"
is actually doing
player.chat = "hello"
#a            player.account
#a(float)    players[float].account
#m            player.ani
              ani
#m(float)    players[float].ani
#K(float)    getascii(float)
#8            player.bodyimg
              bodyimg
#8(float)    players[float].bodyimg
#c            player.chat
              chat
#c(float)    players[float].chat
#C0          player.colors[0]
              colors[0]
#C0(float)    players[float].colors[0]
#C1          player.colors[1]
              colors[1]
#C1(float)    players[float].colors[1]
#C2          player.colors[2]
              colors[2]
#C2(float)    players[float].colors[2]
#C3          player.colors[3]
              colors[3]
#C3(float)    players[float].colors[3]
#C4          player.colors[4]
              colors[4]
#C4(float)    players[float].colors[4]
#C5          player.colors[5]
              colors[5]
#C5(float)    players[float].colors[5]
#D            downloadfile()
#E            emoticonchar()
#e(float,float,oldstring)
              string.substring(float,float)
#g            player.guild
              guild
#g(float)    players[float].guild
#3            player.headimg
              headimg
#3(float)    players[float].headimg
#5            player.horseimg
              horseimg
#5(float)    players[float].horseimg
#k(float)    keyname(float)
#L            player.level
#I(oldstring,float)
              getstring(string)[float]
#n            player.nick
              nick
#n(float)    players[float].nick
#f            image
#f(float)    npcs[float].image
#F            level
#p(float)    params[float]
#P(float)    player.attr[float]
              attr[float]
#P(float,float)
              players[float].attr[float]
#P1          player.attr[1]
              attr[1]
#P1(float)    players[float].attr[1]
#P2          player.attr[2]
              attr[2]
#P2(float)    players[float].attr[2]
#P3          player.attr[3]
              attr[3]
#P3(float)    players[float].attr[3]
#P4          player.attr[4]
              attr[4]
#P4(float)    players[float].attr[4]
#P5          player.attr[5]
              attr[5]
#P5(float)    players[float].attr[5]
#P6          player.attr[6]
              attr[6]
#P6(float)    players[float].attr[6]
#P7          player.attr[7]
              attr[7]
#P7(float)    players[float].attr[7]
#P8          player.attr[8]
              attr[8]
#P8(float)    players[float].attr[8]
#P9          player.attr[9]
              attr[9]
#P9(float)    players[float].attr[9]
#R(oldstring) string.random()
#2            player.shieldimg
              shieldimg
#2(float)    players[float].shieldimg
#s(oldstring) getstring(string)
#1            player.swordimg
              swordimg
#1(float)    players[float].swordimg
#S            player.sword.script
#t(float)    tokens[float]
#T(oldstring) string.trim()
#v(float)    float
#W            player.weapon.icon
#W(float)    weapons[float].icon
#w            player.weapon.script
#w(float)    weapons[float].script
Compatibility note:
When you use the command setcharprop then the first parameter
is handled differently: instead of changing 'player.chat' it
is changing 'chat', the chat text of the npc. So 'setcharprop #c,hello'
would be translated into
chat = "hello"
while 'setplayerprop #c,hello' is translated into
player.chat = "hello"
In the list above both possibilities are listed.
</pre>
</pre>

Revision as of 06:07, 22 February 2005

1. Introduction

1.1. Why scripts

Scripts bring life into objects and make it easy to 
customize the game. Instead of just placing a stone
into your world, you can make it so that the stone
can be lifted or kicked. Instead of being limited to
some fixed player movement you can rescript it
to let the player jump, strafe and duck. To let the 
player inspect and organize his/her items you can
create some dialogs and display those by script,
e.g. when the player presses a special key.

In Graal the scripting is done in 'Graal Script',
it's looking like Java/C++, but brings some 
additional features for making things easier
for game creators, while on the other hand
running in a sandbox and limiting access to
game-related stuff only.

Graal Script is almost fully compatible to 
the 'old' Graal script used in Graal v1.0 - 3.0,
and is partially compatible to Torque script. 

1.2. NPCs and 'weapons'

There are generally two types of objects in Graal
which have scripts: The first type are the 
non-player-characters (NPCs). The name 'NPC' is
actually used for all visible objects in the game: 
monsters, stones, bushes, houses, ships, plants etc.
Scripts for npcs are most of the time containing
code for moving the npc or for reacting to 
activities of the player, e.g. giving money to
the player when he grabs the npc.
The other type of script-holding objects are the
'weapons'. Those are items in the inventory of
the player, not necessary being weapons. Most of
the time they are actually just scripts which
control the movement of the player, display weapon
graphics, or display menus.

So there are objects in the game which have 
their own script, and players which have a set
of scripts in their invisible backpack.

1.3. Server-side and client-side

Graal is an online game, and there are differences
to standard scripting in offline games.
In offline programs you have access to everything,
anytime. In online games everything is divided
into two parts: the server-side which controls
most things in the game, and the client-side which
displays the game to the player.
Since the client only displays things, it is not
possible to cheat by hacking the client. On client-side
you mainly have code for displaying special effects,
for displaying the GUI (windows, status bars, item menus),
playing sound effects and music. Also the player 
movement is done on client-side.
On the server-side scripts are used to do the more
secure parts of the game engine are implemented,
and things that are the same for all players -
npcs are added, moved, npcs interact with players,
the stats of the players are calculated, the
communication between players is handled.

All scripts for npcs and weapons can contain
server-side code and client-side code. The server-side
code is executed directly on the server, the
client-side code is sent to the client when he
logins and executed separately for each player on
their own computer. Usually the two parts of the script
are divided by line that only contains "//#CLIENTSIDE",
like this:

// Server-side part which is setting the image
// of the npc when it is created
function onCreated() {
  setimg("door.png");
}

//#CLIENTSIDE

// Here follows the client-side part,
// which plays a sound effect when the player
// touchs the npc
function onPlayerTouchsme() {
  play("chest.wav");
}


1.4. Events

In general scripts are made for reacting to 
events - when the npc is created then the script
initializes the attributes of the npc,
when the player says something then the npc is
moving to the player, when the player grabs the
npc then the npc is giving the player some money etc.
So the script is basicly a collection of actions
that are done when special events are happening.
Events can e.g. be the "created" event when the npc
is created, the "playertouchsme" event when the 
player touchs the npc, or the "playerchats" event
when the player says something. To write code reacts
to one of those event, you define an event
function like this:

function onEVENTNAME() {
  // actions
}

When the event is happening, then Graal executes
that scripting function and all commands you 
have added there.
Sometimes the event gives some parameters to the 
event function, then change your function to:

function onEVENTNAME(parameter1, paramater2, ...) {
  // actions
}

By accessing 'parameter1' etc. (you can name
them differently) you can react to the event more
exactly. 

Instead of reacting to events, the npcs and
weapons can also invoke new events. That way 
you can let other npcs doing things. You also
need that if you want to coninuously doing things -
use timeout event for that.

function onCreated() {
  timeout = 1;
}

function onTimeout() {
  // actions
  timeout = 1;
}

In the onCreated event function the script is
setting the timer to 1 second. When that second is
over, then the "timeout" event is invoked on the
npc and the onTimeout event function is executed.
Because it is setting the timeout to 1 second
again, the onTimeout even will occur again after
one second, and so on.



Compatibility note:
In older Graal scripts you will also find the
deprecated way of receiving events:

if (EVENTNAME) {
  // actions
}

That is an if-command outside of any brackets. If
Graal sees that you use such an if-command, then
it will execute the whole script so that the actions
you have written inside the if-command will be
executed too.


2. Basics

2.1. Accessing variables

Graal Script variables are 'variant', that means they are objects
that hold values of different types.
When you assign a value to the variable then it automatically
switches to the right type:

Numeric (floating point):
  var = 1;
String:
  var = "hello";
Object link:
  var = player;
Array (list of objects):
  var = {1,2,3};

You can check the current type with the
type()-function - obj.type() returns
0,1,2,3 for numeric, string, object or array.

2.2. Operators

Addition                  a + b
Substraction              a - b
Mulitplication            a * b
Division                  a / b
Modulus                   a % b
Power                     a ^ b
String Concationation     a @ b
Bool-And                  a && b
Bool-Or                   a || b
Bool-Not                  !a
Negative                  -a
Equal                     a == b
Not-Equal                 a != b
Less                      a < b
Greater                   a > b
Less-Equal                a <= b,  a =< b
Greater-Equal             a >= b,  a => b
In-Range                  a in <b,c>, a in |b,c>, a in <b,c|, a in |b,c|
In-Array                  a in {b,c,...}, {a,b,...} in {c,d,...}
Bitwise-Or                a | b
Bitwise-And               a & b
Bitwise-Shift left        a << b
Bitwise-Shift right       a >> b
Bitwise-Invert            ~a
Bitwise-Xor               a xor b (operator ^ already used for power)
Array-Constructor         {a,b,...}
Empty Array               new [count]
Array Member              a[index]
Function call             a(), a(b,c,...)
Object Attribute          a.b, a.(b)
Post Increment            a++
Post Decrement            a--
Pre Increment             ++a
Pre Decrement             --a
Old String Function       #a
Conditional               a? b : c
Assignment                a = b, a := b
Additive Assignment       a += b
Substractive Assignment   a -= b
Multiplicative Assignment a *= b
Division Assignment       a /= b
Modulus Assignment        a %= b
Power Assignment          a ^= b
Bitwise-Or Assignment     a |= b
Bitwise-And Assignment    a &= b
Shift Left Assignment     a <<= b
Shift Right Assignment    a >>= b
String Append             a @= b

2.3. Standard object functions

For a complete list of functions and attributes of objects
see docu_graalscriptfunctions.txt. The base type of all
objects is "TGraalVar". You can also get the latest list by
calling the executale with "-listscriptfunctions" as 
command-line parameter. 
Here only of the built-in functions:

obj.type()  - gets the type of the var (float 0, string 1, object 2, array 3)
obj.length() - string length
obj.trim()
obj.tokenize([delimiters])
obj.charat(pos)
obj.pos(substring)
obj.starts(string)
obj.ends(string)
obj.substring(index[,length])
obj.size() - array length
obj.subarray(index[,length])
obj.addarray(obj2)
obj.insertarray(index,obj2)
obj.index(obj2) - position of obj2 in the array
obj.clear()
obj.add(obj2)
obj.delete(index)
obj.remove(obj2)
obj.replace(index,obj2)
obj.insert(index,obj2)

2.4. Standard functions

format(format,parameters,...) - formats a "%s %d" string, inserts the parameters, and returns a string
int(a)
abs(a)
random(rangestart,rangeend)
sin(a)
cos(a)
arctan(a)
exp(a)
log(base,a)
min(a,b)
max(a,b)
getangle(delta x,delta y)
getdir(delta x,delta y)
vecx(direction)
vecy(direction)

3. Events

3.1. Gui controls

onAdd() when added to the parent
onRemove() when removed from the parent
onWake() when activated
onSleep() when deactivated
onResize(w,h)
onMove(x,y)
onMouseEnter(modifier,x,y,clickcount)
onMouseLeave(modifier,x,y,clickcount)
onMouseDown(modifier,x,y,clickcount)
onMouseUp(modifier,x,y,clickcount)
onMouseDragged(modifier,x,y,clickcount)
onMouseMove(modifier,x,y,clickcount)
onRightMouseDown(modifier,x,y,clickcount)
onRightMouseUp(modifier,x,y,clickcount)
onRightMouseDragged(modifier,x,y,clickcount)
onMouseWheelUp(modifier,x,y,clickcount)
onMouseWheelDown(modifier,x,y,clickcount)
onKeyDown(keycode,string)
onKeyUp(keycode,string)
onKeyRepeat(keycode,string)

3.1.1. GuiMLTextCtrl:

onReflow(w,h) when the text has changed
onURL(url) when clicked on url
onSelectTag(tagid) when clicked on an image

Text-Tags:
The text of multi-line text controls can contain
a few HTML-tags and Torque-tags, you can use both
of those tag types to define colors and fonts
or to include images. Currently following tags
are available:

HTML:
<a href=url> text </a> - when the user clicks on 'text' then 
  a web browser is opened for the specified url
<br> - line break
<font face=fontname size=textsize color=colorname or #rrggbb> text </font>
  - draws text with a special font, size and color; you only
  need to define one of those 3 attributes
<ignorelinebreaks> </ignorelinebreaks> - go into normal HTML mode where
  you need to insert <br> to do a linebreak
<img src=filename id=integer> - an image is displayed, you 
  can also specify a tagid if you want to get onSelectTag-events
  for this image
<p align=left/center/right> - sets the align of the following text
<span style="width=100; height=100;" id=integer> </span> - for 
  displaying a subpage, you can also specifiy an id for 
  onSelectTag-events; instead of <span> you can also use <div> tags

Torque:
<a:url> text </a> - when the user clicks on 'text' then 
  a web browser is opened for the specified url
<bitmap:filename> - an image is displayed
<color:rrggbb> - sets the color of the text (hexadecimal value)
<lmargin:pixels> - sets the left margin for the text
<lmargin%:percent> - sets the size of the left margin depending 
  on the width of the whole control
<linkcolor:rrggbb> - sets the color of links (the <a>-tag)
<linkcolorhl:rrggbb> - sets the highlighted color, when
  the user moves the mouse over a link
<just:left/center/right> - sets the align of the following text
<rmargin:pixels> - sets the right margin for the text
<rmargin%:percent> - sets the size of the right margin depending 
  on the width of the whole control
<sbreak> - line break
<spush> - switches to a new style (like <font>)
<spop> - switches back to the last saved style (like </font>)
<tab:tab1,tab2,..> - sets the position of where tabulators should
  be displayed if you have text like 'Apple \t Egg \t Chicken'
<tag:id> - inserts an invisible tag which can be used
  for the scrollToTag(id) function (beside image-tags)


3.1.2. GuiTextEditCtrl:

onTabComplete()
onAction(text) when return key pressed

3.1.3. GuiTextListCtrl:

onSelect(id,text) when row selected
onDblClick(id) when double-click on row or return key pressed
onDeleteKey(id) when delete key pressed
onIconResized(w,h) when setIconSize() called
onOpenMenu(0,index,text) when an item was right-clicked

3.1.4. GuiPopUpMenuCtrl:

onSelect(id,text) when menu option choosen
onCancel() when menu is closed without action
onOpenMenu(0,index,text) when an item was right-clicked

3.1.5. GuiMenuBar:

onMenuSelect(menuid,menutext)
onMenuItemSelect(menuid,menutext,itemid,itemtext)

3.1.6. GuiTreeViewCtrl:

onSelect(id,rightmouse) when row selected
onUnselect(id) when row de-selected
onInspect(id) when clicked on the name of an item
onOpenMenu(0,index,text) when an item was right-clicked
onContextMenu("x y",id) when clicked with right-mouse key on row


4. Old script compatibility

4.1. Removed functionality

- toinventory
- followplayer
- playersays()
- setbackpal

4.2. Supported old scripting commands & their mapping to new script

addstring oldstring, oldstring;
                                addstring(string,string);
addtiledef oldstring, oldstring, float;
                                addtiledef(string,string,float);
addtiledef2 oldstring, oldstring, float, float;
                                addtiledef2(string,string,float,float);
attachplayertoobj float, float;
                                attachplayertoobj(float,float);
blockagain;
                                blockagain();
blockagainlocal;
                                blockagainlocal();
callnpc float, oldstring;
                                callnpc(float,string);
callweapon float, oldstring;
                                callweapon(float,string);
canbecarried;
                                canbecarried();
canbepulled;
                                canbepulled();
canbepushed;
                                canbepushed();
cannotbecarried;
                                cannotbecarried();
cannotbepulled;
                                cannotbepulled();
cannotbepushed;
                                cannotbepushed();
canwarp;
                                canwarp();
canwarp2;
                                canwarp2();
carryobject oldstring;
                                carryobject(string);
changeimgcolors float, float, float, float, float;
                                changeimgcolors(float,float,float,float,float);
changeimgmode float, float;
                                changeimgmode(float,float);
changeimgpart float, float, float, float, float;
                                changeimgpart(float,float,float,float,float);
changeimgvis float, float;
                                changeimgvis(float,float);
changeimgzoom float, float;
                                changeimgzoom(float,float);
deletestring oldstring, float;
                                deletestring(string,float);
destroy;
                                destroy();
detachplayer;
                                detachplayer();
disabledefmovement;
                                disabledefmovement();
disablemap;
                                disablemap();
disablepause;
                                disablepause();
disableselectweapons;
                                disableselectweapons();
disableweapons;
                                disableweapons();
dontblock;
                                dontblock();
dontblocklocal;
                                dontblocklocal();
drawaslight;
                                drawaslight();
drawoverplayer;
                                drawoverplayer();
drawunderplayer;
                                drawunderplayer();
enabledefmovement;
                                enabledefmovement();
enablefeatures float;
                                enablefeatures(float);
enablemap;
                                enablemap();
enablepause;
                                enablepause();
enableselectweapons;
                                enableselectweapons();
enableweapons;
                                enableweapons();
explodebomb float;
                                explodebomb(float);
followplayer;
                                followplayer();
freezeplayer float;
                                freezeplayer(float);
freezeplayer2;
                                freezeplayer2();
hide;
                                hide();
hideimg float;
                                hideimg(float);
hideimgs float, float;
                                hideimgs(float,float);
hidelocal;
                                hidelocal();

hitcompu float, float, float, float;
                                hitcompu(float,float,float,float);
hitnpc float, float, float, float;
                                hitnpc(float,float,float,float);
hitobjects float, float, float;
                                hitobjects(float,float,float);
hideplayer float;
                                hideplayer(float);
hidesword float;
                                hidesword(float);
hitplayer float, float, float, float;
                                hitplayer(float,float,float,float);
hurt float;
                                hurt(float);
insertstring oldstring, float, oldstring;
                                insertstring(string,float,string);
join oldstring;
                                join(string);
lay oldstring;
                                lay(string);
lay2 oldstring, float, float;
                                lay2(string,float,float);
loadmap oldstring;
                                loadmap(string);
message oldstring;
                                message(string);
move float, float, float, float;
                                move(float,float,float,float);
noplayerkilling;
                                noplayerkilling();
openurl oldstring;
                                openurl(string);
openurl2 oldstring, float, float;
                                openurl2(string,float,float);
play oldstring;
                                play(string);
play2 oldstring, float, float, float;
                                play2(string,float,float,float);
playlooped oldstring;
                                playlooped(string);
putbomb float, float, float;
                                putbomb(float,float,float);
putcomp oldstring, float, float;
                                putcomp(string,float,float);
putexplosion float, float, float;
                                putexplosion(float,float,float);
putexplosion2 float, float, float, float;
                                putexplosion2(float,float,float,float);
puthorse oldstring, float, float;
                                puthorse(string,float,float);
putleaps float, float, float;
                                putleaps(float,float,float);
putnewcomp oldstring, float, float, oldstring, float;
                                putnewcomp(string,float,float,string,float);
putnpc oldstring, oldstring, float, float;
                                putnpc(string,string,float,float);
putnpc2 float, float, oldstring;
                                putnpc2(float,float,string);
reflectarrow float;
                                reflectarrow(float);
removearrow float;
                                removearrow(float);
removebomb float;
                                removebomb(float);
removecompus;
                                removecompus();
removeexplo float;
                                removeexplo(float);
removehorse float;
                                removehorse(float);
rmeoveitem float;
                                removeitem(float)
removestring oldstring, oldstring;
                                removestring(string,string);
removetiledefs oldstring;
                                removetiledefs(string);
replaceani oldstring, oldstring;
                                replaceani(string,string);
replacestring oldstring, float, oldstring;
                                replacestring(string,float,string);
resetfocus;
                                resetfocus();
savelog oldstring;
                                savelog(string);
savelog2 oldstring, oldstring;
                                savelog2(string,string);
say float;
                                say(float);
say2 oldstring;
                                say2(string);
sendrpgmessage oldstring;
                                sendrpgmessage(string);
sendpm oldstring;
                                sendpm(string);
sendtonc oldstring;
                                sendtonc(string);
sendtorc oldstring;
                                sendtorc(string);
serverwarp oldstring;
                                serverwarp(string);
set oldstring;
                                set(string);
setani oldstring, oldstring;
                                setani(string,string);
setarray float, float;
                                setarray(var,float);
setbeltcolor oldstring;
                                setbeltcolor(string);
setbow oldstring;
                                setbow(string);
setcharani oldstring, oldstring;
                                setcharani(string,string);
setchargender oldstring;
                                setchargender(string);
setcharprop oldstring, oldstring;
                                string = string;
setcoatcolor oldstring;
                                setcoatcolor(string);
setcoloreffect float, float, float, float;
                                setcoloreffect(float,float,float,float);
setcursor float;
                                setcursor(float);
setcurcor2 oldstring;
                                setcursor2(string);
seteffect float, float, float, float;
                                seteffect(float,float,float,float);
seteffectmode float;
                                seteffectmode(float);
setfocus float, float;
                                setfocus(float,float);
setgender oldstring;
                                setgender(string);
sethead oldstring;
                                sethead(string);
setlevel oldstring;
                                setlevel(string);
setlevel2 oldstring, float, float;
                                setlevel2(string,float,float);
setmap oldstring, oldstring, float, float;
                                setmap(string,string,float,float);
setminimap oldstring, oldstring, float, float;
                                setminimap(string,string,float,float);
setmusicvolume float, float;
                                setmusicvolume(float,float);
setimg oldstring;
                                setimg(string);
setimgpart oldstring, float, float, float, float;
                                setimgpart(string,float,float,float,float);
setletters oldstring;
                                setletters(string);
setplayerdir oldstring;
                                setplayerdir(string);
setplayerprop oldstring, oldstring;
                                string = string;
setpm oldstring;
                                setpm(string);
setshape float, float, float;
                                setshape(float,float,float);
setshape2 float, float, float;
                                setshape2(float,float,float);
setshield oldstring, float;
                                setshield(string,float);
setshoecolor oldstring;
                                setshoecolor(string);
setshootparams oldstring;
                                setshootparams(string);
setskincolor oldstring;
                                setskincolor(string);
setsleevecolor oldstring;
                                setsleevecolor(string);
setstring oldstring, oldstring;
                                setstring(string,string);
setsword oldstring, float;
                                setsword(string,float);
seturllevel oldstring;
                                seturllevel(string);
setz float, float, float, float, float, float, float, float;
                                setz(float,float,float,float,float,float,float,float);
setzoomeffect float;
                                setzoomeffect(float);
shoot float, float, float, float, float, float, oldstring, oldstring;
                                shoot(float,float,float,float,float,float,string,string);
shootarrow float;
                                shootarrow(float);
shootball;
                                shootball();
shootfireball float;
                                shootfireball(float);
shootfireblast float;
                                shootfireblast(float);
shootnuke float;
                                shootnuke(float);
show;
                                show();
showani float, float, float, float, oldstring;
                                showani(float,float,float,float,string);
showani2 float, float, float, float, float, oldstring;
                                showani2(float,float,float,float,float,string);
showcharacter;
                                showcharacter();
showfile oldstring;
                                showfile(string);
showimg float, oldstring, float, float;
                                showimg(float,string,float,float);
showimg2 float, oldstring, float, float, float;
                                showimg2(float,string,float,float,float);
showlocal;
                                showlocal();

showpoly float, float;
                                showpoly(float,array);
showpoly2 float, float;
                                showpoly2(float,array);
showstats float;
                                showstats(float);
showtext float, float, float, oldstring, oldstring, oldstring;
                                showtext(float,float,float,string,string,string);
showtext2 float, float, float, float, oldstring, oldstring, oldstring;
                                showtext2(float,float,float,float,string,string,string);
sleep float;
                                sleep(float);
spyfire float, float;
                                spyfire(float,float);
stopmidi;
                                stopmidi();
stopsound oldstring;
                                stopsound(string);
take oldstring;
                                take(string);
take2 float;
                                take2(float);
takehorse float;
                                takehorse(float);
takeplayercarry;
                                takeplayercarry();
takeplayerhorse;
                                takeplayerhorse();
throwcarry;
                                throwcarry();
timereverywhere;
                                timereverywhere();
timershow;
                                timershow();
toinventory oldstring;
                                toinventory(string);
tokenize oldstring;
                                tokens = string.tokenize();
tokenize2 oldstring, oldstring;
                                tokens = string.tokenize(" ," @ string);
toweapons oldstring;
                                toweapons(string);
triggeraction float, float, oldstring, oldstring;
                                triggeraction(float,float,string,string);
unfreezeplayer;
                                unfreezeplayer();
unset oldstring;
                                unset(string);
updateboard float, float, float, float;
                                updateboard(float,float,float,float);
updateterrain;
                                updateterrain();
wraptext float, oldstring, oldstring;
                                tokens = wraptext(float," ," @ string,string);
wraptext2 float, float, oldstring, oldstring;
                                tokens = wraptext2(float,float," ," @ string,string);

4.3. Supported old scripting functions & their mapping to new script

4.4. Supported old string operations

These old string operators can be used in string parameters
for the old commands, also you can use them directly as operators, e.g.
#c = "hello"
is actually doing
player.chat = "hello"

#a            player.account
#a(float)     players[float].account
#m            player.ani
              ani
#m(float)     players[float].ani
#K(float)     getascii(float)
#8            player.bodyimg
              bodyimg
#8(float)     players[float].bodyimg
#c            player.chat
              chat
#c(float)     players[float].chat
#C0           player.colors[0]
              colors[0]
#C0(float)    players[float].colors[0]
#C1           player.colors[1]
              colors[1]
#C1(float)    players[float].colors[1]
#C2           player.colors[2]
              colors[2]
#C2(float)    players[float].colors[2]
#C3           player.colors[3]
              colors[3]
#C3(float)    players[float].colors[3]
#C4           player.colors[4]
              colors[4]
#C4(float)    players[float].colors[4]
#C5           player.colors[5]
              colors[5]
#C5(float)    players[float].colors[5]
#D            downloadfile()
#E            emoticonchar()
#e(float,float,oldstring)
              string.substring(float,float)
#g            player.guild
              guild
#g(float)     players[float].guild
#3            player.headimg
              headimg
#3(float)     players[float].headimg
#5            player.horseimg
              horseimg
#5(float)     players[float].horseimg
#k(float)     keyname(float)
#L            player.level
#I(oldstring,float)
              getstring(string)[float]
#n            player.nick
              nick
#n(float)     players[float].nick
#f            image
#f(float)     npcs[float].image
#F            level
#p(float)     params[float]
#P(float)     player.attr[float]
              attr[float]
#P(float,float)
              players[float].attr[float]
#P1           player.attr[1]
              attr[1]
#P1(float)    players[float].attr[1]
#P2           player.attr[2]
              attr[2]
#P2(float)    players[float].attr[2]
#P3           player.attr[3]
              attr[3]
#P3(float)    players[float].attr[3]
#P4           player.attr[4]
              attr[4]
#P4(float)    players[float].attr[4]
#P5           player.attr[5]
              attr[5]
#P5(float)    players[float].attr[5]
#P6           player.attr[6]
              attr[6]
#P6(float)    players[float].attr[6]
#P7           player.attr[7]
              attr[7]
#P7(float)    players[float].attr[7]
#P8           player.attr[8]
              attr[8]
#P8(float)    players[float].attr[8]
#P9           player.attr[9]
              attr[9]
#P9(float)    players[float].attr[9]
#R(oldstring) string.random()
#2            player.shieldimg
              shieldimg
#2(float)     players[float].shieldimg
#s(oldstring) getstring(string)
#1            player.swordimg
              swordimg
#1(float)     players[float].swordimg
#S            player.sword.script
#t(float)     tokens[float]
#T(oldstring) string.trim()
#v(float)     float
#W            player.weapon.icon
#W(float)     weapons[float].icon
#w            player.weapon.script
#w(float)     weapons[float].script

Compatibility note:
When you use the command setcharprop then the first parameter
is handled differently: instead of changing 'player.chat' it
is changing 'chat', the chat text of the npc. So 'setcharprop #c,hello'
would be translated into
chat = "hello"
while 'setplayerprop #c,hello' is translated into
player.chat = "hello"
In the list above both possibilities are listed.