Thursday, 30 September 2010

Week 2: To make the object(Pandora's Box) detect avatars(Agents) within a certain radius.

Using a for loop starting at 0, i.e. the first index of the detected agent array, I gave some output based on that index. And execution:

With a greeting message.


















Only by clicking the object again the search takes place, as they were no one in the sandbox i managed to find myself.  :p

Here the screenshot of the code and execution:


default
{
    state_entry()
    {
        llOwnerSay("Hello, Avatar! How are you today?");
    }

    touch_start(integer total_number)
    {
        llSay(0, " Please Wait Searching for agents");
        //searches for avatars and gets the owner names
        if (llDetectedOwner(0) == llGetOwner())
        {
            //executes if owner is touching
            llSensor("", NULL_KEY, AGENT, 50, PI);
        }
        else
        {
            //executes if another avatar is touching
            llSensor("", NULL_KEY, AGENT, 25, PI);
        }
      
    }
  
    sensor(integer total_number)
    {   //number of owners tracked in the search radius
        llSay(0, (string)total_number + " agents in search radius");
        integer i;
        for (i = 0; i < total_number; i++)
        {   //outputs the results of no.of avatars detected
            llSay(0, "You've been detected, " + llDetectedName(i));
        }
    }
}

No comments:

Post a Comment