Aw instance

From ActiveWiki
Jump to: navigation, search

Minimum requirements
Added in version 2.1
SDKbuild 13

void* aw_instance (void)


Returns the current instance.


None (returns immediately)


One instance will always be the current instance at any given moment. In multi-instance applications the current instance will constantly change in response to calls to the API and for events or callbacks. At any given time an application can query the current instance by calling this method.

The return value of aw_user_data could also be used to identify the current instance. But, only if a user-defined data pointer has been set for it, and only if part of the data it points to is different for each instance.

See Multiple instances for more information.



Argument attributes


Return values

Pointer to the current instance, NULL if there is none.

Returned attributes



#define MAX_BOTS 3

void (*instance)[MAX_BOTS];

static char* chat_type[] = {"said", "broadcasted", "whispered"};

void handle_chat (void)
  int i;
  for (i = 0; i < MAX_BOTS; i++)
    if (aw_instance () == instance[i])
  printf ("(instance #%d) %s %s %s\n",
    aw_string (AW_AVATAR_NAME),
    chat_type[ aw_int (AW_CHAT_TYPE)],
    aw_string (AW_CHAT_MESSAGE));

int main (int argc, char *argv[])
  int i;
  aw_init (AW_BUILD);
  for (i = 0; i < MAX_BOTS; i++)
    aw_create (NULL, 0, &instance[i]);
  aw_event_set (AW_EVENT_CHAT, handle_chat);
  /* code here to log in all bots into the universe and into the
     world and to set their positions */
  /* ... */
  aw_wait (-1);
  return 0;

See also