Vp wait: Difference between revisions
Jump to navigation
Jump to search
m Forgot to mention callbacks are fired too |
m Removed reason code |
||
Line 4: | Line 4: | ||
{{sdk parameter row|int|milliseconds|Maximum amount of time to pump (in milliseconds)}} | {{sdk parameter row|int|milliseconds|Maximum amount of time to pump (in milliseconds)}} | ||
|returncodes= | |returncodes= | ||
{{sdk return code row| | {{sdk return code row|not_supported |vp_wait is not supported by this instance, for example a custom vp_net_config was passed to {{sdk method|create}}}} | ||
{{sdk return code row|recursive_wait |vp_wait was called recursively on the same instance}} | |||
{{sdk return code row| | {{sdk return code row|connection_error |Waiting for data failed or there are no connections to wait for events on}} | ||
{{sdk return code row| | |||
|behavior= | |behavior= | ||
* This will attempt to send all pending messages and receive all pending data within the given time limit | * This will attempt to send all pending messages and receive all pending data within the given time limit |
Revision as of 17:15, 17 December 2016
Method call snippet
vp_wait(instance, 1000);
Pumps incoming and outgoing network traffic and fires any registered events. Required for most in-world method calls (e.g. vp_say()
) and events to actually happen.
Parameters
These are the parameters that this method requires:
Parameter | Usage |
---|---|
VPInstance instance |
Pointer to the instance this method call is intended for |
int milliseconds |
Maximum amount of time to pump (in milliseconds) |
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_SUPPORTED |
vp_wait is not supported by this instance, for example a custom vp_net_config was passed to vp_create()
|
VP_RC_RECURSIVE_WAIT |
vp_wait was called recursively on the same instance |
VP_RC_CONNECTION_ERROR |
Waiting for data failed or there are no connections to wait for events on |
Behavior
- This will attempt to send all pending messages and receive all pending data within the given time limit
- All SDK events and SDK callbacks are fired from this method call. Consequently, they are fired on the same thread as the caller.
- If a value of
0
is passed, it could still fire a number of different events - If there is nothing to handle, it will wait until the time limit. Else, it will return immediately after handling all pending data
Caveats
This method should never be called inside an event handler originating from a previous vp_wait()
call. Doing so is undefined behavior and may break the internal SDK state. For example:
...
vp_event_set(instance, VP_EVENT_AVATAR_ADD, event_avatar_add);
while(vp_wait(instance, 1000) == 0){}
...
void event_avatar_add(VPInstance sdk)
{
char message[300];
sprintf((char*)&message, "Hello, %s!", vp_string(sdk, VP_AVATAR_NAME));
vp_say(sdk, (char*)&message);
vp_wait(instance, 1000); // Undefined behavior
}
Examples
- This method has no usage examples; please add at least one to this page