Difference between revisions of "Path update"

From Second Life Wiki
Jump to navigation Jump to search
(Replaced the fixed numbers with the pre-defined constants associated with pathfinding events.)
m (some minor memory usage improvement)
Line 17: Line 17:
     state_entry()
     state_entry()
     {
     {
         llDeleteCharacter(); // Clear any previous character behaviors
    //  Clear any previous character behaviors
         llCreateCharacter([CHARACTER_MAX_SPEED, 25, CHARACTER_DESIRED_SPEED, 15.0]);
         llDeleteCharacter();
        //MAX_SPEED is @ 20 by default
 
          
    // MAX_SPEED is @ 20 by default
         llWanderWithin(llGetPos(), <10.0, 10.0,  10.0>, []);
         llCreateCharacter([
            CHARACTER_MAX_SPEED, 25.0,
            CHARACTER_DESIRED_SPEED, 15.0]);
 
         vector currentPosition = llGetPos();
         llWanderWithin(currentPosition, <10.0, 10.0,  10.0>, []);
     }
     }
   
 
     path_update(integer type, list reserved)
     path_update(integer type, list reserved)
     {
     {
        string info;
         if (type == PU_SLOWDOWN_DISTANCE_REACHED)
         if (type == PU_SLOWDOWN_DISTANCE_REACHED)
        {
             info = "Near";
             llOwnerSay("Near");
 
        }
         else if (type == PU_GOAL_REACHED)
         else if (type == PU_GOAL_REACHED)
        {
             info = "Stopping";
             llOwnerSay("Stopping");
 
        }
         else if (type == PU_FAILURE_INVALID_START)
         else if (type == PU_FAILURE_INVALID_START)
         {
         {
             llOwnerSay("Cannot path find from current location! Attempting to go to the center of the region.");
             info = "Cannot path find from current location! Attempting "
              
                    + "to go to the center of the region.";
             llNavigateTo(<128.0, 128.0, llGround(<128.0, 128.0, 0.0> - llGetPos())>, [FORCE_DIRECT_PATH, TRUE]);
 
             vector currentPosition = llGetPos();
             llNavigateTo(<128.0, 128.0, llGround(<128.0, 128.0, 0.0> - currentPosition)>, [FORCE_DIRECT_PATH, TRUE]);
         }
         }
         else if (type == PU_FAILURE_INVALID_GOAL)
         else if (type == PU_FAILURE_INVALID_GOAL)
        {
             info = "Goal not on navmesh!";
             llOwnerSay("Goal not on navmesh!");
 
        }
         else if (type == PU_FAILURE_UNREACHABLE)
         else if (type == PU_FAILURE_UNREACHABLE)
        {
             info = "Goal unreachable!";
             llOwnerSay("Goal unreachable!");
 
        }
         else if (type == PU_FAILURE_TARGET_GONE)
         else if (type == PU_FAILURE_TARGET_GONE)
        {
             info = "Target gone!";
             llOwnerSay("Target gone!");
 
        }
         else if (type == PU_FAILURE_NO_VALID_DESTINATION)
         else if (type == PU_FAILURE_NO_VALID_DESTINATION)
        {
             info = "No place to go!";
             llOwnerSay("No place to go!");
 
        }
         else if (type ==  PU_EVADE_HIDDEN)
         else if (type ==  PU_EVADE_HIDDEN)
        {
             info = "Hiding from pursuer...";
             llOwnerSay("Hiding from pursuer...");
 
        }
         else if (type == PU_EVADE_SPOTTED)
         else if (type == PU_EVADE_SPOTTED)
        {
             info = "Switched from hiding to running...";
             llOwnerSay("Switched from hiding to running...");
 
        }
         else if (type ==  PU_FAILURE_NO_NAVMESH)
         else if (type ==  PU_FAILURE_NO_NAVMESH)
        {
             info = "Region has no nav mesh..";
             llOwnerSay("Region has no nav mesh..");
 
        }
         else if (type == PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED)
         else if (type == PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED)
        {
             info = "Dynamic pathfinding is disabled in this region.";
             llOwnerSay("Dynamic pathfinding is disabled in this region.");
 
        }
         else if (type == PU_FAILURE_PARCEL_UNREACHABLE)
         else if (type == PU_FAILURE_PARCEL_UNREACHABLE)
        {
             info = "Parcel entry problem (is the parcel full?).";
             llOwnerSay("Parcel entry problem (is the parcel full?).");
 
        }
         else if (type == PU_FAILURE_OTHER)
         else if (type == PU_FAILURE_OTHER)
        {
             info = "Hit an unspecified failure";
             llOwnerSay("Hit an unspecified failure");
 
        }
         else
         else
        {
             info = "Unknown failure";
             llOwnerSay("Unknown failure");
 
         }
        key owner = llGetOwner();
         llRegionSayTo(owner, PUBLIC_CHANNEL, info);
     }
     }
}
}
</lsl>  
</lsl>  
|also_functions=
|also_functions=

Revision as of 09:39, 8 October 2012

Description

Event: path_update( integer type, list reserved ){ ; }

Event description goes here.

• integer type A PU_*, it's the path event type
• list reserved Reserved; not currently used.
Constants Value Description
PU_SLOWDOWN_DISTANCE_REACHED 0x00 Character is near current goal.
PU_GOAL_REACHED 0x01 Character has reached the goal and will stop or choose a new goal (if wandering).
PU_FAILURE_INVALID_START 0x02 Character cannot navigate from the current location - e.g., the character is off the navmesh or too high above it.
PU_FAILURE_INVALID_GOAL 0x03 Goal is not on the navmesh and cannot be reached.
PU_FAILURE_UNREACHABLE 0x04 Goal is no longer reachable for some reason - e.g., an obstacle blocks the path.
PU_FAILURE_TARGET_GONE 0x05 Target (for llPursue or llEvade) can no longer be tracked - e.g., it left the region or is an avatar that is now more than about 30m outside the region.
PU_FAILURE_NO_VALID_DESTINATION 0x06 There's no good place for the character to go - e.g., it is patrolling and all the patrol points are now unreachable.
PU_EVADE_HIDDEN 0x07 Triggered when an llEvade character thinks it has hidden from its pursuer.
PU_EVADE_SPOTTED 0x08 Triggered when an llEvade character switches from hiding to running
PU_FAILURE_NO_NAVMESH 0x09 This is a fatal error reported to a character when there is no navmesh for the region. This usually indicates a server failure and users should file a bug report and include the time and region in which they received this message.
PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED 0x0A Triggered when a character enters a region with dynamic pathfinding disabled. Dynamic pathfinding can be toggled by estate managers via the 'dynamic_pathfinding' option in the Region Debug Console.
PU_FAILURE_PARCEL_UNREACHABLE 0x0B Triggered when a character failed to enter a parcel because it is not allowed to enter, e.g. because the parcel is already full or because object entry was disabled after the navmesh was baked.
PU_FAILURE_OTHER 0xF4240 Other failure.

Caveats

All Issues ~ Search JIRA for related Bugs

Examples

<lsl> default {

   state_entry()
   {
   //  Clear any previous character behaviors
       llDeleteCharacter();
   //  MAX_SPEED is @ 20 by default
       llCreateCharacter([
           CHARACTER_MAX_SPEED, 25.0,
           CHARACTER_DESIRED_SPEED, 15.0]);
       vector currentPosition = llGetPos();
       llWanderWithin(currentPosition, <10.0, 10.0,  10.0>, []);
   }
   path_update(integer type, list reserved)
   {
       string info;
       if (type == PU_SLOWDOWN_DISTANCE_REACHED)
           info = "Near";
       else if (type == PU_GOAL_REACHED)
           info = "Stopping";
       else if (type == PU_FAILURE_INVALID_START)
       {
           info = "Cannot path find from current location! Attempting "
                   + "to go to the center of the region.";
           vector currentPosition = llGetPos();
           llNavigateTo(<128.0, 128.0, llGround(<128.0, 128.0, 0.0> - currentPosition)>, [FORCE_DIRECT_PATH, TRUE]);
       }
       else if (type == PU_FAILURE_INVALID_GOAL)
           info = "Goal not on navmesh!";
       else if (type == PU_FAILURE_UNREACHABLE)
           info = "Goal unreachable!";
       else if (type == PU_FAILURE_TARGET_GONE)
           info = "Target gone!";
       else if (type == PU_FAILURE_NO_VALID_DESTINATION)
           info = "No place to go!";
       else if (type ==  PU_EVADE_HIDDEN)
           info = "Hiding from pursuer...";
       else if (type == PU_EVADE_SPOTTED)
           info = "Switched from hiding to running...";
       else if (type ==  PU_FAILURE_NO_NAVMESH)
           info = "Region has no nav mesh..";
       else if (type == PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED)
           info = "Dynamic pathfinding is disabled in this region.";
       else if (type == PU_FAILURE_PARCEL_UNREACHABLE)
           info = "Parcel entry problem (is the parcel full?).";
       else if (type == PU_FAILURE_OTHER)
           info = "Hit an unspecified failure";
       else
           info = "Unknown failure";
       key owner = llGetOwner();
       llRegionSayTo(owner, PUBLIC_CHANNEL, info);
   }

} </lsl>

Deep Notes

Signature

event void path_update( integer type, list reserved );