Aw state change

From ActiveWiki
Jump to: navigation, search


Minimum requirements
Added in version 2.1
SDKbuild 13


int aw_state_change (void)

Description

Informs the world server of your avatar's current state.

Callback

None (returns immediately)

Notes

An instance must call this method at least once per world in order to receive any of the following events in that world, unless the bot is in global mode:

This method triggers AW_EVENT_AVATAR_CHANGE events in all other nearby clients that are tracking avatars.

The SDK will limit itself to sending at most AW_WORLD_AVATAR_REFRESH_RATE state changes per second (in the Active Worlds Browser it would be under World Features, General, Avatar Updates per second). If this limit is exceeded then aw_state_change will return RC_NOT_YET. Either keep calling aw_state_change until it succeeds again or aw_wait (as per normal operation) until the SDK automatically updates the state (seems to delay a full second). The maximum number of updates per second can never exceed AW_MAX_AVCHANGE_PER_SECOND (defined in Aw.h).

Arguments

None

Argument attributes

AW_MY_X
AW_MY_Y
AW_MY_Z
AW_MY_YAW
AW_MY_TYPE
AW_MY_GESTURE
AW_MY_PITCH
AW_MY_STATE

Return values

RC_SUCCESS
RC_NOT_INITIALIZED
RC_NO_INSTANCE
RC_NO_CONNECTION
The connection to the world is down.
RC_NOT_YET
It would exceed the maximum number of state changes per second.

Returned attributes

None

Usage

Old example:

int yaw;
int rc;

/* spin on a dime (45 degrees/second) */
for (yaw = 0; !aw_wait (1000); yaw += 450)
{
  aw_int_set (AW_MY_YAW, yaw);
  rc = aw_state_change ();
  if (rc != RC_SUCCESS && rc != RC_NOT_YET)
    break;
}

Smoother movement (version 3.4 and later):

int yaw;
int rate = aw_int (AW_WORLD_AVATAR_REFRESH_RATE);
int rc;

/* spin on a dime (45 degrees/second) as smoothly as possible */
for (yaw = 0; !aw_wait (1000 / rate); yaw += 450 / rate)
{
  aw_int_set (AW_MY_YAW, yaw);
  rc = aw_state_change ();
  if (rc != RC_SUCCESS && rc != RC_NOT_YET)
    break;
}

See also