Vp float: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{sdk method page|float|Return the value of | {{sdk method page|float|Return the value of a floating point attribute. | ||
|paramex=attr | |paramex=attr | ||
|parameters= | |parameters= | ||
{{sdk parameter row|vp_float_attribute_t|attr|Attribute to return value of}} | {{sdk parameter row|vp_float_attribute_t|attr|Attribute to return value of (defined in VP.h)}} | ||
|returns= | |returns= | ||
float | float | ||
|behavior | |behavior=If an invalid value is passed for <i>attr</i>, then 0 will be returned. | ||
|caveats=There is no way to know if the call was unsuccessful, use {{sdk method|float_get}} when this is required. Also, when higher precision is desired, use {{sdk method|double}}. | |||
|examples= | |examples= | ||
<syntaxhighlight lang="c"> | |||
void handle_avatar_add(VPInstance sdk) | |||
{ | |||
float x, z; | |||
x = vp_float(sdk, VP_AVATAR_X); | |||
z = vp_float(sdk, VP_AVATAR_Z); | |||
// If an avatar appears at roughly 0X 0Z (at any height), then send a welcome message. | |||
if (x > -0.5 && x < 0.5 && y > -0.5 && y < 0.5) | |||
{ | |||
char msg[256]; | |||
sprintf(msg, "Welcome %s to the world!", vp_string(VP_AVATAR_NAME)); | |||
vp_say(sdk, msg); | |||
} | |||
} | |||
int main(int argc, const char* argv[]) | |||
{ | |||
//... | |||
vp_event_set(sdk, VP_EVENT_AVATAR_ADD, handle_avatar_add); | |||
//... | |||
} | |||
</syntaxhighlight> | |||
|seealso= | |seealso= | ||
* {{sdk method|float_get}} | * {{sdk method|float_get}} | ||
* {{sdk method|float_set}} | * {{sdk method|float_set}} | ||
}} | }} |
Revision as of 19:34, 12 December 2016
Method call snippet
vp_float(instance, attr);
Return the value of a floating point attribute.
Parameters
These are the parameters that this method requires:
Parameter | Usage |
---|---|
VPInstance instance |
Pointer to the instance this method call is intended for |
vp_float_attribute_t attr |
Attribute to return value of (defined in VP.h) |
Returns
float
Behavior
If an invalid value is passed for attr, then 0 will be returned.
Caveats
There is no way to know if the call was unsuccessful, use vp_float_get()
when this is required. Also, when higher precision is desired, use vp_double()
.
Examples
void handle_avatar_add(VPInstance sdk)
{
float x, z;
x = vp_float(sdk, VP_AVATAR_X);
z = vp_float(sdk, VP_AVATAR_Z);
// If an avatar appears at roughly 0X 0Z (at any height), then send a welcome message.
if (x > -0.5 && x < 0.5 && y > -0.5 && y < 0.5)
{
char msg[256];
sprintf(msg, "Welcome %s to the world!", vp_string(VP_AVATAR_NAME));
vp_say(sdk, msg);
}
}
int main(int argc, const char* argv[])
{
//...
vp_event_set(sdk, VP_EVENT_AVATAR_ADD, handle_avatar_add);
//...
}