@c -*-texinfo-*-
@node User Objects in Maps, , User Objects, Game Data
@subsection Attaching User Objects to CS Objects in a map file
@cindex user objects in map files
@cindex @code{iObject}
@cindex @code{csObject}
@cindex @code{iKeyValuePair}
@cindex @code{iObjectIterator}

In the previous howto (@pxref{User Objects}) you could see how
you can attach game data to Crystal Space objects at runtime (i.e. from
within code). It is also possible to attach game data to objects through
the map file. Here we explain how.

@subsubheading Using Key/Value Pairs

Crystal Space doesn't do anything with the keys you specify in a map file.
The only thing it does is store them so you can use them later. Here is
how you would fetch all keys from a mesh object:

@example
void MyGame::ProcessKeys (iMeshWrapper* mesh)
@{
  csRef<iObjectIterator> it = mesh->QueryObject ()->GetIterator ();
  while (it->HasNext ())
  @{
    iObject* obj = it->Next ();
    csRef<iKeyValuePair> key = scfQueryInterface<iKeyValuePair> (obj);
    if (key)
    @{
      if (!strcmp (key->GetKey (), "monsterAI"))
      @{
        // Process key->GetValue ()
        @dots{}
      @}
      else if (!strcmp (key->GetKey (), "monsterLive"))
      @{
        // Process key->GetValue ()
        @dots{}
      @}
    @}
  @}
@}
@end example

This is only an example. You can call @code{QueryObject} on almost every
Crystal Space object and loop over all keys (or other @code{iObject}
implementing objects) with the code above.

To actually process the key you could check out the previous
tutorial (@pxref{User Objects}) and make your own game data object
that contains all the collected values and attach that to the mesh too.

@subsubheading Include Files

The include files useful for this section are:

@example
#include <iutil/object.h>
#include <csutil/csobject.h>
#include <cstool/keyval.h>
@end example

