vp_object_add

From Virtual Paradise Wiki
Revision as of 21:55, 16 December 2016 by Sleepy E (talk | contribs) (Add example, some information on attributes)
Jump to navigation Jump to search
Method call snippet vp_object_add(instance);

Build a new object.

Parameters

These are the parameters that this method requires:

Parameter Usage
VPInstance
instance
Pointer to the instance this method call is intended for

Used attributes

This method uses data set in these attributes when called:

Attribute Usage
VP_OBJECT_TYPE Type of object (0 - 3D Model, 2 - Particle emitter, 3 - Path object)
VP_OBJECT_X X coordinate
VP_OBJECT_Y Y coordinate
VP_OBJECT_Z Z coordinate
VP_OBJECT_ROTATION_X Rotation X axis
VP_OBJECT_ROTATION_Y Rotation Y axis
VP_OBJECT_ROTATION_Z Rotation Z axis
VP_OBJECT_ROTATION_ANGLE Rotation angle in radians
VP_OBJECT_YAW Yaw angle in degrees (these are used instead of X,Y,Z axis when rotation angle is set to INFINITE)
VP_OBJECT_PITCH Pitch angle in degrees
VP_OBJECT_ROLL Roll angle in degrees
VP_OBJECT_MODEL Model
VP_OBJECT_ACTION Action
VP_OBJECT_DESCRIPTION Description
VP_OBJECT_DATA Data

Returns

This method returns a return code integer, which indicates whether the call was successful or errored for any reason:

Return code Cause
VP_RC_SUCCESS Successful call (for methods that have a registered callback, it only means the request has been sent)
VP_RC_NOT_IN_WORLD Bot is not currently in a world

The following attributes will be returned in VP_CALLBACK_OBJECT_ADD if the operation was successful:

Attribute Usage Also returned for
VP_OBJECT_ID Object id that was assigned to the new object

Behavior

  • Upon successful creation of an object, VP_EVENT_OBJECT is triggered for those who have subscribed to it.

Examples

Build a street1.rwx object at 0X 0Y 0Z.

void handle_object_add(VPInstance sdk, int rc, int ref)
{
  if (rc)
    printf("Couldn't build object (reason %d)\n", rc);
  else
    printf("Object built successfully!\n");
}

int main(int argc, const char* argv[])
{
  //...
  
  vp_callback_set(sdk, VP_CALLBACK_OBJECT_ADD, handle_object_add);

  vp_int_set(sdk, VP_OBJECT_TYPE, 0); // 3D Model
  vp_float_set(sdk, VP_OBJECT_X, 0.0);
  vp_float_set(sdk, VP_OBJECT_Y, 0.0);
  vp_float_set(sdk, VP_OBJECT_Z, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_X, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_Y, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_Z, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_ANGLE, 0.0);
  vp_string_set(sdk, VP_OBJECT_MODEL, "street1.rwx");
  vp_string_set(sdk, VP_OBJECT_ACTION, "");
  vp_string_set(sdk, VP_OBJECT_DESCRIPTION, "");
	
  rc = vp_object_add(sdk);
  if (rc)
    printf("Couldn't build object (reason %d)\n", rc);

  //...
}

See also