Difference between revisions of "LSL Example Pathfinding Wanderer"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "This is a pathfinding test script, which is a simple wandering character. <lsl> // wandering box; touch me to start wandering de…")
 
m (changed <pre> to <syntaxthighlight lang="lsl2">)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This is a [[Pathfinding_in_Second_Life|pathfinding]] test script, which is a simple [[LlWanderWithin|wandering]] character.
This is a [[Pathfinding_in_Second_Life|pathfinding]] test script, which is a simple [[LlWanderWithin|wandering]] character.
<lsl>
<syntaxhighlight lang="lsl2">
// wandering box; touch me to start wandering
// wandering box; touch me to start wandering
default
default
Line 76: Line 76:
         llOwnerSay("path_update: " + (string)type + ": " + update_desc);
         llOwnerSay("path_update: " + (string)type + ": " + update_desc);
     }
     }
}</lsl>
}</syntaxhighlight>

Latest revision as of 08:53, 25 February 2017

This is a pathfinding test script, which is a simple wandering character.

// wandering box; touch me to start wandering
default
{
    on_rez(integer reznum)
    {
        llResetScript();
    }
    state_entry()
    {
        llSay(0, "Touch me to trigger wandering");
        llDeleteCharacter();
        llCreateCharacter([]);        
    }
    touch_start(integer detected)
    {
        llWanderWithin(llGetPos(), <20.0, 20.0, 5.0>, []);
    }
    path_update(integer type, list reserved)
    {
        string update_desc;

        if (type == PU_SLOWDOWN_DISTANCE_REACHED)
        {
            update_desc = "Near";
        }
        else if (type == PU_GOAL_REACHED)
        {
            update_desc = "Stopping";
        }
        else if (type == PU_FAILURE_INVALID_START)
        {
            update_desc = "Cannot path find from current location!";
        }
        else if (type == PU_FAILURE_INVALID_GOAL)
        {
            update_desc = "Goal not on navmesh!";
        }
        else if (type == PU_FAILURE_UNREACHABLE)
        {
            update_desc = "Goal unreachable!";
        }
        else if (type == PU_FAILURE_TARGET_GONE)
        {
            update_desc = "Target gone!";
        }
        else if (type == PU_FAILURE_NO_VALID_DESTINATION)
        {
            update_desc = "No place to go!";
        }
        else if (type == PU_EVADE_HIDDEN)
        {
            update_desc = "I am hidden from my pursuer";
        }
        else if (type == PU_EVADE_SPOTTED)
        {
            update_desc = "I was found by my pursuer";
        }
        else if (type == PU_FAILURE_NO_NAVMESH)
        {
            update_desc = "Error: there is no navmesh for this region?!";
        }
        else if(type == PU_FAILURE_DYNAMIC_PATHFINDING_DISABLED)
        {
            update_desc = "Dynamic pathfinding is disabled in this region";
        }
        else if(type == PU_FAILURE_PARCEL_UNREACHABLE)
        {
            update_desc = "Failed to enter a parcel - is it full?";
        }
        else
        {
            update_desc = "Erm... Not a known value!";
        }
        llOwnerSay("path_update: " + (string)type + ": " + update_desc);
    }
}