Difference between revisions of "User/Digit Ditko/experience hud basic script"
< User
Jump to navigation
Jump to search
Digit Ditko (talk | contribs) |
Digit Ditko (talk | contribs) |
||
Line 130: | Line 130: | ||
</source> | </source> | ||
Revision as of 20:04, 12 September 2015
HUD Experience Detection
If you need a HUD that will activate and inactivate itself as an avatar moves about Second Life™ then this example shows the minimum necessary to do that.
// the color of the HUD for the active mode
vector ACTIVE_COLOR = <0.0, 1.0, 0.0>;
// the color of the HUD in inactive mode
vector INACTIVE_COLOR = <1.0, 0.0, 0.0>;
// simple function to change the HUD color.
setColor (vector inColor)
{
llSetLinkPrimitiveParamsFast (
LINK_SET, [PRIM_COLOR, ALL_SIDES, inColor, 1.0]);
}
// -----------------------------------------------------------------------------
// Default state
// The default state is the logical "inactive" state of the HUD.
default
{
state_entry ()
{
// for the initial setup of the HUD, just set the color to inactive.
setColor (INACTIVE_COLOR);
// after the setup is complete , determing is the HUD should go
// to the active state. If the script is NOT compiled to use an
// experience, then the agent in experience API call will return false.
if (llAgentInExperience (llGetOwner ()))
{
state active;
}
}
attach (key inAvatar)
{
// if the HUD is beinf attached, check if the agent is in the experience
// and swich to the active state.
if (inAvatar)
{
if (llAgentInExperience (inAvatar))
{
state active;
}
}
}
changed (integer inMask)
{
// if the owner changes or if the avatar goes to a different
// region, chesk it the avatar is in the experience again and
// change to the active state if neeed.
if (inMask & (CHANGED_REGION | CHANGED_OWNER))
{
key av = llGetOwner ();
if (llAgentInExperience (av))
{
state active;
}
}
}
}
// --------------------------------------------------------------------------
// in the "active" state the HUD should have all standard functions.
// All this demo script does is turn the HUD to the active color.
state active
{
state_entry ()
{
// set the HUD color to active.
// This would usually be more elabotrate in a real script
setColor (ACTIVE_COLOR);
}
on_rez (integer inParam)
{
// When the object is trezzed, the state of the HUD is unknown.
// Just change to the default state to run through the initialization
// logic as needed.
state default;
}
attach (key inAvatar)
{
// when attached, check if the agent is in the experience and
// change to the default inactive state ias needed.
if (inAvatar)
{
if (! llAgentInExperience (inAvatar))
{
state default;
}
}
}
changed (integer inMask)
{
// need to go through initialization logic if the owner changes or if
// the avatar goes to a different region. NOTE: This does not detect
// individual parcel changes.
if (inMask & (CHANGED_REGION | CHANGED_OWNER))
{
key av = llGetOwner ();
if (! llAgentInExperience (av))
{
state default;
}
}
}
}