]> de.git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Introduction_to_QuakeC.markdown
Fix case of all links.
[xonotic/xonotic.wiki.git] / Introduction_to_QuakeC.markdown
1 QuakeC
2 ======
3
4 {{\>toc}}
5
6 Article TODO
7 ------------
8
9 -   expand explanations
10
11 About QuakeC
12 ------------
13
14 QuakeC is a very simplified dialect of the well-known C programming language, and is used by the Quake I engine and its derivatives. Xonotic uses the FTEQCC dialect of QuakeC, so only this dialect will be described (as well as some common extensions among Quake engines).
15
16 Example code
17 ------------
18
19 To see what QuakeC looks like, here is a piece of example code:
20
21       // needed declarations:
22       float vlen(vector v) = #12;
23       entity nextent(entity e) = #47;
24       .string classname;
25       .vector origin;
26       // ...
27       entity findchain(.string fld, string match)
28       {
29         entity first, prev;
30         entity e;
31         first = prev = world;
32         for(e = world; (e = nextent(e)); ++e)
33           if(e.fld == match)
34           {
35             e.chain = world;
36             if(prev)
37               prev.chain = e;
38             else
39               first = e;
40             prev = e;
41           }
42         return first;
43       }
44       // ...
45       entity findnearestspawn(vector v)
46       {
47         entity nearest;
48         entity e;
49         for(e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
50           if(!nearest)
51             nearest = e;
52           else if(vlen(e.origin - v) < vlen(nearest.origin - v))
53             nearest = e;
54         return nearest;
55       }
56
57 **Note:** *findchain* is implemented in QuakeC for demonstration purposes only so one can see how to build a linked list, as this function is already built in to the engine and can be used directly
58
59 Other resources
60 ---------------
61
62 Here is a forum on Inside3D where you can read more about QuakeC and ask questions:
63 \* QuakeC Forum on Inside3D: http://forums.inside3d.com/viewforum.php?f=2
64 \* QC Tutorial for Absolute Beginners: http://forums.inside3d.com/viewtopic.php?t=1286
65
66 For available functions in QuakeC, look in the following places:
67 \* The Quakery: http://quakery.quakedev.com/qwiki/index.php/List\_of\_builtin\_functions
68 \* Xonotic source: [builtins.qh](http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob_plain;f=qcsrc/server/builtins.qh;hb=HEAD) for Quake functions, [extensions.qh](http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob_plain;f=qcsrc/server/extensions.qh;hb=HEAD) for DarkPlaces extensions
69
70 Variables
71 =========
72
73 Declaring
74 ---------
75
76 To declare a variable, the syntax is the same as in C:
77
78       float i;
79
80 However, variables cannot be initialized in their declaration for historical reasons, and trying to do so would define a constant.
81
82 Whenever a variable declaration could be interpreted as something else by the compiler, the *var* keyword helps disambiguating. For example,
83
84       float(float a, float b) myfunc;
85
86 is an old-style function declaration, while
87
88       var float(float a, float b) myfunc;
89
90 declares a variable of function type. An alternate and often more readable way to disambiguate variable declarations is using a *typedef*, like so:
91
92       typedef float(float, float) myfunc_t;
93       myfunc_t myfunc;
94
95 Scope
96 -----
97
98 A variable declared in the global scope has global scope, and is visible starting from its declaration to the end of the code. The order the code is read in by the compiler is defined in the file progs.src.
99 A variable declared inside a function has block scope, and is visible starting from its declaration to the end of the smallest block that contains its declaration.
100
101 Some variables are declared in [sys.qh](http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob_plain;f=qcsrc/server/sys.qh;hb=HEAD). Their declarations or names should never be changed, as they have to match the order and names of the variables in the file file [progdefs.h](http://svn.icculus.org/twilight/trunk/darkplaces/progdefs.h?view=markup) of the engine exactly, or the code won’t load. The special markers *end\_sys\_globals* and *end\_sys\_fields* are placed to denote the end of this shared declaration section.
102
103 Types
104 =====
105
106 Quake only knows four elementary data types: the basic types *float*, *vector*, *string*, and the object type *entity*. Also, there is a very special type of types, *fields*, and of course *functions*. FTEQCC also adds *arrays*, although these are slow and a bit buggy. Note that there are no pointers!
107
108 float
109 -----
110
111 This is the basic numeric type in QuakeC. It represents the standard 32bit floating point type as known from C. It has 23 bits of mantissa, 8 bits of exponent, and one sign bit. The numeric range goes from about 1.175e-38 to about 3.403e+38, and the number of significant decimal digits is about six.
112
113 As float has 23 bits of mantissa, it can also be used to safely represent integers in the range from ~~16777216 to 16777216. 16777217 is the first integer *float* can not represent.
114 Common functions for *float* are especially *ceil*, *floor* , and *random*, which yields a random number *r* with *0 \<= r \< 1*.
115 h2. vector
116 This type is basically three floats together. By declaring a *vector v*, you also create three floats *v\_x*, *v\_y* and *v\_z* that contain the components of the vector.
117 Vectors can be used with the usual mathematical operators in the usual way used in mathematics. For example, *vector + vector* simply returns the sum of the vectors, and *vector \* float* scales the vector by the given factor. Note however that dividing a vector by a float is NOT supported, one has to use *vector \* \_ instead. Multiplying two vectors yields their dot product of type float.
118 Common functions to be used on vectors are*vlen\_ , *normalize* .
119 Vector literals are written like ‘1 0 0’.
120 **COMPILER BUG:** Always use *vector = vector \* float* instead of *vector **= float*, as the latter creates incorrect code!
121 h2. string
122 A*string\_ in QuakeC is an immutable reference to a null-terminated character string stored in the engine. It is not possible to change a character in a string, but there are various functions to create new strings:
123 ** **ftos** and **vtos** convert*floats\_ and *vectors* to strings. Their inverses are, of course, *stof* and *stov*, which parse a *string* into a *float* or a *vector*.
124 \* **strcat** concatenates 2 to 8 strings together, as in:
125 \<pre\><code class="c">
126 strcat"abc";
127 \</code\>\</pre\>
128
129 \* \*strstrofs(haystack, needle, offset)\* searches for an occurrence of one string in another, as in:
130 \<pre\>\<code class="c"\>
131 strstrofs("haystack", "ac", 0)5;
132 </code>\</pre\>
133 The offset defines from which starting position to search, and the return value is *~~1\_ if no match is found. The offset returned is *0*~~based, and to search in the whole string, a start offset of*0\_ would be used.
134 \* **substring\* returns part of a string. The offset is *0*~~based here, too.
135 Note that there are different kinds of *strings*, regarding memory management:
136 \* **Temporary strings** are strings returned by built-in string handling functions such as *substring*, *strcat*. They last only for the duration of the function call from the engine. That means it is safe to return a temporary string in a function you wrote, but not to store them in global variables or objects as their storage will be overwritten soon.
137 \* **Allocated strings** are strings that are explicitly allocated. They are returned by *strzone* and persist until they are freed . Note that *strzone* does not change the string given as a parameter, but returns the newly allocated string and keeps the passed temporary string the same way! That means:
138 **\* To allocate a string, do for example:
139 \<pre\><code class="c">
140 myglobal = strzone);
141 </code>\</pre\>
142 **\* To free the string when it is no longer needed, do:
143 \<pre\><code class="c">
144 strunzone;
145 </code>\</pre\>
146 \* **Engine-owned strings**, such as *netname*. These should be treated just like temporary strings: if you want to keep them in your own variables, *strzone* them.
147 \* **Constant strings:** A string literal like *“foo”* gets permanent storage assigned by the compiler. There is no need to *strzone* such strings.
148 \* **The null string:** A global uninitialized *string* variable has the special property that is is usually treated like the constant, empty, string *“”* , but it is the only string that evaluates to FALSE in an if expression . As this is a useful property, Xonotic code declares such a string variable of the name *string\_null*. That means that the following patterns are commonly used for allocating strings:
149 **\* Assigning to a global string variable:
150 \<pre\>
151 if
152  strunzone;
153 myglobal = strzone;
154 \</pre\>
155 **\* Freeing the global string variable:
156 \<pre\>
157 if
158  strunzone;
159 myglobal = string\_null;
160 \</pre\>
161 **\* Checking if a global string value has been set:
162 \<pre\>
163 if {
164  value has been set;
165 }
166 else {
167  string has not yet been set;
168 }
169 \</pre\>
170 h2. entity
171 The main object type in QuakeC is *entity*, a reference to an engine internal object. An *entity* can be imagined as a huge struct, containing many *fields*. This is the only object type in the language. However, *fields* can be added to the *entity* type by the following syntax:
172 \<pre\>
173 .float myfield;
174 \</pre\>
175 and then all objects *e* get a field that can be accessed like in *e.myfield*.
176 The special entity *world* also doubles as the *null* reference. It can not be written to other than in the *spawnfunc\_worldspawn* function that is run when the map is loaded, and is the only entity value that counts as *false* in an *if* expression. Thus, functions that return *entities* tend to return *world* to indicate failure .
177 If a field has not been set, it gets the usual zero value of the type when the object is created .
178 h2. fields
179 A reference to such a field can be stored too, in a field variable. It is declared and used like
180 \<pre\>
181  .float myfield;
182  // …
183  // and in some function:
184  var .float myfieldvar;
185  myfieldvar = myfield;
186  e.myfieldvar = 42;
187 \</pre\>Field variables can be used as function parameters too - in that case you leave the *var* keyword out, as it is not needed for disambiguation.
188 h2. functions
189 Functions work just like in C:
190 \<pre\>
191  float sum3
192  {
193  return a + b + c;
194  }\</pre\>
195 However, the syntax to declare function pointers is simplified:
196 \<pre\>
197  typedef float op3func\_t;
198  var float f;
199  op3func\_t g;
200  f = sum3;
201  g = f;
202  print), “”); // prints 6
203 \</pre\>
204 Also note that the *var* keyword is used again to disambiguate from a global function declaration.
205 In original QuakeC by iD Software, this simplified function pointer syntax also was the only way to define functions :
206 \<pre\>
207  float sum2 = {
208  return a + b;
209  }
210 \</pre\>
211 A special kind of functions are the built-in functions, which are defined by the engine. These are imported using so-called built-in numbers, with a syntax like:
212 \<pre\>
213  string strcat = \#115;
214 \</pre\>
215 h2. void
216 Just like in C, the *void* type is a special placeholder type to declare that a function returns nothing. However, unlike in C, it is possible to declare variables of this type, although the only purpose of this is to declare a variable name without allocating space for it. The only occasion where this is used is the special *end\_sys\_globals* and *end\_sys\_fields* marker variables.
217 h2. arrays
218 As the QuakeC virtual machine provides no pointers or similar ways to handle arrays, array support is added by FTEQCC and very limited. Arrays can only be global, must have a fixed size , and are a bit buggy and slow. Almost as great as in FORTRAN, except they can’t be multidimensional either!
219 You declare arrays like in C:
220 \<pre\>
221  \#define MAX\_ASSASSINS 16
222  entity assassins[MAX\_ASSASSINS];
223  \#define BTREE\_MAX\_CHILDREN 5
224  .entity btree\_child[BTREE\_MAX\_CHILDREN];
225  \#define MAX\_FLOATFIELDS 3
226  var .float myfloatfields[MAX\_FLOATFIELDS];
227 \</pre\>
228 The former is a global array of entities and can be used the usual way:
229 \<pre\>
230  assassins[self.assassin\_index] = self;
231 \</pre\>
232 The middle one is a global array of entity fields and****not**\* a field of array type , so its usage looks a bit strange:
233 \<pre\>
234 for
235  self. = world;
236 \</pre\>
237 Note that this works:
238 \<pre\>
239 var .entity indexfield;
240 indexfield = btree\_child[i];
241 self.indexfield = world;
242 \</pre\>
243 The latter one is a global array of entity field variables, and looks very similar:
244 \<pre\>
245 myfloatfields[2] = health;
246 self. = 0;
247 // equivalent to self.health = 0;
248 \</pre\>
249 Do not use arrays when you do not need to~~ using both arrays and function calls in the same expression can get messed up , and arrays are slowly emulated using functions *ArrayGet\*myfloatfields* and *ArraySet\*myfloatfields* the compiler generates that internally do a binary search for the array index.
250 h1. Peculiar language constructs
251 This section deals with language constructs in FTEQCC that are not similar to anything in other languages.
252 h2. if not
253 There is a second way to do a negated *if*:
254  if not
255  …
256 It compiles to slightly more efficient code than
257  if
258  …
259 and has the notable difference that
260  if not
261  …
262 will not execute , but
263  if
264  …
265 will execute .
266
267 h1. Common patterns
268 Some patterns in code that are often encountered in Xonotic are listed here, in no particular order.
269 h2. Classes in Quake
270 The usual way to handle classes in Quake is using *fields*, function pointers and the special property *classname*.
271 But first, let’s look at how the engine creates entities when the map is loaded.
272 Assume you have the following declarations in your code:
273  entity self;
274  .string classname;
275  .vector origin;
276  .float height;
277 and the engine encounters the entity
278  {
279  “classname” “func\_bobbing”
280  “height” “128”
281  “origin” “0 32 ~~64"
282  }
283 then it will, during loading the map, behave as if the following QuakeC code was executed:
284  self = spawn;
285  self.classname = "func\_bobbing";
286  self.height = 128;
287  self.origin = ’0 32~~64’;
288  spawnfunc\_func\_bobbing();
289 We learn from this:
290  \* The special global *entity* variable *self* is used when”methods" of an object are called, like - in this case - the “constructor” or spawn function *spawnfunc\_func\_bobbing*.
291 ** Before calling the spawn function, the engine sets the mapper specified fields to the values. String values can be treated by the QC code as if they are constant strings, that means there is no need to *strzone* them.
292  \* Spawn functions always have the *spawnfunc*\_ name prefix and take no arguments.
293  \* The *string* field *classname* always contains the name of the entity class when it was created by the engine.
294  \* As the engine uses this pattern when loading maps and this can’t be changed, it makes very much sense to follow this pattern for all entities, even for internal use. Especially making sure *classname* is set to a sensible value is very helpful.
295 Methods are represented as fields of function type:
296  .void think;
297 and are assigned to the function to be called in the spawn function, like:
298  void func\_bobbing\_think
299  {
300  // lots of stuff
301  }
302  void spawnfunc\_func\_bobbing
303  {
304  // … even more stuff …
305  self.think = func\_bobbing\_think;
306  }
307 To call a method of the same object, you would use
308  self.think;
309 but to call a method of another object, you first have to set *self* to that other object, but you typically need to restore *self* to its previous value when done:
310  entity oldself;
311  // …
312  oldself = self;
313  self.think;
314  self = oldself;
315 h2. Think functions
316 A very common entry point to QuakeC functions are so-called think functions.
317 They use the following declarations:
318  .void think;
319  .float nextthink;
320 If *nextthink* is not zero, the object gets an attached timer: as soon as *time* reaches *nextthink*, the *think* method is called with *self* set to the object. Before that, *nextthink* is set to zero. So a typical use is a periodic timer, like this:
321  void func\_awesome\_think
322  {
323  bprint;
324  self.nextthink = time + 2;
325  }
326  void spawnfunc\_func\_awesome
327  {
328  // …
329  self.think = func\_awesome\_think;
330  self.nextthink = time + 2;
331  }
332 h2. Find loops
333 One common way to loop through entities is the find loop. It works by calling a built-in function like
334  entity find = \#18;
335 repeatedly. This function is defined as follows:
336  \* if *start* is *world*, the first entity *e* with *e.fieldmatch\_ is returned
337   \* otherwise, the entity \_e\_ \*\*after\*\* \_start\_ in the entity order with \_e.fieldmatch* is returned
338  \* if no such entity exists, *world* is returned
339 It can be used to enumerate all entities of a given type, for example *“info\_player\_deathmatch”*:
340  entity e;
341  for); )
342  print, “”);
343 There are many other functions that can be used in find loops, for example *findfloat*, *findflags*, *findentity*.
344 Note that the function *findradius* is misnamed and is not used as part of a find loop, but instead sets up a linked list of the entities found.
345 h2. Linked lists
346 An alternate way to loop through a set of entities is a linked list. I assume you are already familiar with the concept, so I’ll skip information about how to manage them.
347 It is however noteworthy that some built-in functions create such linked lists using the *entity* field *chain* as list pointer. Some of these functions are the aforementioned *findradius*, and *findchain*, *findchainfloat*, *findchainflags* and *findchainentity*.
348 A loop like the following could be used with these:
349  entity e;
350  for; e; e = e.chain)
351  print, “”);
352 The main advantage of linked lists however is that you can keep them in memory by using other fields than *chain* for storing their pointers. That way you can avoid having to search all entities over and over again when you commonly need to work with the same type of entities.
353 h2. Error handling
354 Error handling is virtually non-existent in QuakeC code. There is no way to throw and handle exceptions.
355 However, built-in functions like *fopen* return *~~1\_ on error.
356 To report an error condition, the following means are open to you:
357  \* Use the *print* function to spam it to the console. Hopefully someone will read that something went wrong. After that, possibly use *remove* to delete the entity that caused the error .
358  \* Use the *error* function to abort the program code and report a fatal error with a backtrace showing how it came to it.
359  \* Use the *objerror* function to abort spawning an entity . This also prints an error message, and the entity that caused the error will not exist in game. Do not forget to *return* from the spawn function directly after calling *objerror*!
360 h2. target and targetname
361 In the map editor, entities can be connected by assigning a name to them in the *target* field of the targeting entity and the *targetname* field of the targeted entity.
362 To QuakeC, these are just strings~~ to actually use the connection, one would use a find loop:
363  entity oldself;
364  oldself = self;
365  for); )
366  self.use;
367  self = oldself;
368
369 h2. the enemy field and its friends
370 As the find loop for*target\_ and *targetname* causes the engine to loop through all entities and compare their *targetname* field, it may make sense to do this only once when the map is loaded.
371 For this, a common pattern is using the pre-defined *enemy* field to store the target of an entity.
372 However, this can’t be done during spawning of the entities yet, as the order in which entities are loaded is defined by the map editor and tends to be random. So instead, one should do that at a later time, for example when the entity is first used, in a think function, or~~ the preferred way in the Xonotic code base - in an *InitializeEntity* function:
373
374 void teleport\_findtarget()
375  {
376  // …
377  self.enemy = find(world, targetname, self.target);
378  if(!self.enemy)
379  // some error handling…
380  // …
381  }
382
383 void spawnfunc\_trigger\_teleport()
384  {
385  // …
386  InitializeEntity(self, teleport\_findtarget, INITPRIO\_FINDTARGET);
387  // …
388  }
389
390 *InitializeEntity* functions are guaranteed to be executed at the beginning of the next frame, before the *think* functions are run, and are run in an order according to their priorities (the *INITPRIO*\_ constants).
391
392 if-chains
393 ---------
394
395 With default compile options (i.e. if the option *~~flo\_ is not passed to the compiler), boolean expressions are evaluated fully. This means that in
396  if)
397  …
398 *SomeCompexFunction* is always evaluated, even if *flag* is true. To avoid this, one can use:
399  if
400  if)
401  …
402 h2. Tracing
403
404 h1. Pitfalls and compiler bugs
405 h2. complex operators
406 Do not count on the modifying and reading operators like *+=* or *++* to always work. Using them in simple cases like:
407  a *= 42;
408  for
409  …
410 is generally safe, but complex constructs like:
411  self.enemy.frags*= self.value—;
412 are doomed. Instead, split up such expressions into simpler steps:
413  self.enemy.frags = self.enemy.frags + self.value;
414  self.value~~= 1;
415 The compiler warning **RETURN VALUE ALREADY IN USE** is a clear indicator that an expression was too complex for it to deal with it correctly. If you encounter the warning, do make sure you change the code to no longer cause it, as the generated code **will** be incorrect then.
416 Also, do not use the*+=\_ like operators on *vector\_s, as they are known to create incorrect code and only operate on the*x\_ component of the vector.
417
418 functions VS. arrays
419 --------------------
420
421 Mixing function calls with array dereferencing, or doing more than one array dereferencing in the same expression, is known to create incorrect code. Avoid constructs like:
422
423 print(ftos(floatarray[i]), " —\> “, stringarray[i], anotherstringarray[i],”“);
424 as the array dereferencings and the *ftos* return value are likely to overwrite each other. Instead, simplify it:
425 \<pre\>
426 float f;
427 string s, s2;
428 // …
429 f = floatarray[i];
430 s = stringarray[i];
431 s2 = anotherstringarray[i];
432 print(ftos(f),” —\> “, s, s2,”“);
433 \</pre\>
434 h2. vectoangles does not match makevectors
435 The pitch angle is inverted between these two functions. You have to negate the pitch (i.e. the *x* component of the vector representing the euler angles) to make it fit the other function.
436 As a rule of thumb, *vectoangles* returns angles as stored in the *angles* field (used to rotate entities for display), while *makevectors* expects angles as stored in the *v\_angle* field (used to transmit the direction the player is aiming). There is about just as much good reason in this as there is for 1:1 patch cables. Just deal with it.
437 h1. Entry points
438 The server-side code calls the following entry points of the QuakeC code:
439  \* **void ClientDisconnect**: called when a player leaves the server. Do not forget to *strunzone* all *strings* stored in the player entity here, and do not forget to clear all references to the player!
440 ****void SV\_Shutdown()**: called when the map changes or the server is quit. A good place to store persistent data like the database of race records.
441 ** **void SV\_ChangeTeam**: called when a player changes his team. Can be used to disallow team changes, or to clear the player’s scores.
442 ****void ClientKill()**: called when the player uses the "kill" console command to suicide.
443 ** **void RestoreGame**: called directly after loading a save game. Useful to, for example, load the databases from disk again.
444 ****void ClientConnect()**: called as soon as a client has connected, downloaded everything, and is ready to play. This is the typical place to initialize the player entity.
445 ** **void PutClientInServer**: called when the client requests to spawn. Typically puts the player somewhere on the map and lets him play.
446 ****.float SendEntity(entity to, float sendflags)**: called when the engine requires a CSQC networked entity to send itself to a client, referenced by *to*. Should write some data to *MSG\_ENTITY*. *FALSE* can be returned to make the entity not send. See *EXT\_CSQC* for information on this.
447 ** **void URI\_Get\_Callback**:
448 ****void GameCommand(string command)**: called when the "sv\_cmd" console command is used, which is commonly used to add server console commands to the game. It should somehow handle the command, and print results to the server console.
449 ** **void SV\_OnEntityNoSpawnFunction**: called when there is no matching spawn function for an entity. Just ignore this…
450 ****void SV\_OnEntityPreSpawnFunction**: called before even looking for the spawn function, so you can even change its classname in there. If it removes the entity, the spawn function will not be looked for.
451 ** **void SV\_OnEntityPostSpawnFunction**: called ONLY after its spawn function or SV\_OnEntityNoSpawnFunction was called, and skipped if the entity got removed by either.
452  \* **void SetNewParms**:
453 ****void SetChangeParms()**:
454 ** **.float customizeentityforclient**: called for an entity before it is going to be sent to the player specified by *other*. Useful to change properties of the entity right before sending, e.g. to make an entity appear only to some players, or to make it have a different appearance to different players.
455 ****.void touch()**: called when two entities touch; the other entity can be found in *other*. It is, of course, called two times .
456 ** **.void contentstransition**:
457 ****.void think()**: described above, basically a timer function.
458 ** **.void blocked**: called when a *MOVETYPE\_PUSH* entity is blocked by another entity. Typically does either nothing, reverse the direction of the door moving, or kills the player who dares to step in the way of the Mighty Crusher Door.
459 ****.void movetypesteplandevent()**: called when a player hits the floor.
460 ** **.void PlayerPreThink**: called before a player runs his physics. As a special exception, *frametime* is set to 0 if this is called for a client-side prediction frame, as it still will get called for server frames.
461 ****.void PlayerPreThink()**: called after a player runs his physics. As a special exception, *frametime* is set to 0 if this is called for a client-side prediction frame, as it still will get called for server frames.
462 ** **void StartFrame**: called at the beginning of each server frame, before anything else is done.
463 ****void EndFrame()**: called at the end of each server frame, just before waiting until the next frame is due.
464 ** **void SV\_PlayerPhysics**: allows to replace the player physics with your own code. The movement the player requests can be found in the *vector* field *movement*, and the currently pressed buttons are found in various fields, whose names are aliased to the *BUTTON*\_ macros.
465 ****void SV\_ParseClientCommand(string command)\*: handles commands sent by the client to the server using”cmd …". Unhandled commands can be passed to the built-in function *clientcommand* to execute the normal engine behaviour.