Difference between revisions of "LlDetectedTouchFace"

From Second Life Wiki
Jump to navigation Jump to search
m (oops)
m
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{LSL_Function/detected|index|TouchFace|simple=*}}{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/detected|index|touchFace|simple=*}}
|func_id=338|func_sleep=0.0|func_energy=10.0
|func_id=338|func_sleep=0.0|func_energy=10.0
|func=llDetectedTouchFace
|func=llDetectedTouchFace
Line 13: Line 14:
** The event triggered is not a {{LSLGC|Touch|touch}} event.
** The event triggered is not a {{LSLGC|Touch|touch}} event.
|examples=
|examples=
<lsl>
<source lang="lsl2">
default {
// This is the essential script to drop in a prim when you need to ascertain the number of a face (or faces)
// Touch the prim surfaces to learn their face numbers, which you can then use in other scripts for texturing, colouring etc.


     touch_start(integer num_detected) {
say(string message)
         integer i;
{
         for (i = 0; i < num_detected; i++) {
    llSay(PUBLIC_CHANNEL, message);
             integer touchedFace = llDetectedTouchFace(i);    
}
 
default
{
     touch_start(integer num_detected)
    {
         integer face = llDetectedTouchFace(0);
 
         if (face == TOUCH_INVALID_FACE)
//      {
            say("The touched face could not be determined");
//      }
        else
//      {
            say("You touched face number " + (string) face);
//      }
    }
}
</source>
<source lang="lsl2">
default
{
    touch_start(integer num_detected)
    {
        integer link = llDetectedLinkNumber(0);
        integer face = llDetectedTouchFace(0);
 
        if (face == TOUCH_INVALID_FACE)
            llSay(PUBLIC_CHANNEL, "Sorry, your viewer doesn't support touched faces.");
        else
        {
             // store the original color
            list  colorParams  = llGetLinkPrimitiveParams(link, [PRIM_COLOR, face]);
            vector originalColor = llList2Vector(colorParams, 0);


             if (touchedFace == -1) {
             // color detected face white
                llWhisper(0, "Sorry, your viewer doesn't support touched faces.");
            llSetLinkColor(link, <1.0, 1.0, 1.0>, face);
             }
             llSleep(0.2);
            else {
                // Store away the original color
                vector oldColor = llGetColor(touchedFace);


                // Flash white and black on the touched face
            // color detected face black
                llSetColor(<1., 1., 1.>, touchedFace);
            llSetLinkColor(link, ZERO_VECTOR, face);
                llSleep(0.1);
            llSleep(0.2);
                llSetColor(<0., 0., 0.>, touchedFace);
                llSleep(0.1);
               
                // Put the color back to how we found it.
                llSetColor(oldColor, touchedFace);
            } // if ...
        } // for ...
    } // touch_start


            // color detected face back to original color
            llSetLinkColor(link, originalColor, face);
        }
    }
}
}
</lsl>
</source>
|helpers
|helpers
|related
|related
Line 59: Line 87:
|history=*Introduced in Viewer {{SVN|870|rev=92872|branch=Release|anchor=file14|date=Wednesday, 23 July 2008}}.
|history=*Introduced in Viewer {{SVN|870|rev=92872|branch=Release|anchor=file14|date=Wednesday, 23 July 2008}}.
*Server support available in Second Life Server 1.24.7.98039, client support in Release Candidate viewer 1.21.4 (98167)
*Server support available in Second Life Server 1.24.7.98039, client support in Release Candidate viewer 1.21.4 (98167)
*Date of Release Server [[ Release_Notes/Second_Life_Beta_Server/1.24#Release_Notes_for_Second_Life_Beta_Server_1.24.3_.28August_29th.2C_2008.29 | 29-08-2008 ]]
*Date of Release Client  [[ Release_Notes/Second_Life_Release/1.21 | 16-10-2008 ]]
|cat1=Touch
|cat1=Touch
|cat2=Face
|cat2=Face

Latest revision as of 00:58, 22 January 2015

Summary

Function: integer llDetectedTouchFace( integer index );

Returns an integer that is the index of the face the avatar clicked on.

• integer index Index of detection information

index does not support negative indexes. For the touch category of events only. The prim that was touched may not be the prim receiving the event, use llDetectedLinkNumber to check for this; likewise you can use llDetectedTouchFace to determine which face was touched.

Caveats

  • If index is out of bounds the script continues to execute without an error message.
  • TOUCH_INVALID_FACE is returned when...
    • The avatar's viewer does not support face touch detection.
    • The touch has moved off the surface of the prim.
    • The event triggered is not a touch event.
All Issues ~ Search JIRA for related Bugs

Examples

// This is the essential script to drop in a prim when you need to ascertain the number of a face (or faces)
// Touch the prim surfaces to learn their face numbers, which you can then use in other scripts for texturing, colouring etc.

say(string message)
{
    llSay(PUBLIC_CHANNEL, message);
}

default
{
    touch_start(integer num_detected)
    {
        integer face = llDetectedTouchFace(0);

        if (face == TOUCH_INVALID_FACE)
//      {
            say("The touched face could not be determined");
//      }
        else
//      {
            say("You touched face number " + (string) face);
//      }
    }
}
default
{
    touch_start(integer num_detected)
    {
        integer link = llDetectedLinkNumber(0);
        integer face = llDetectedTouchFace(0);

        if (face == TOUCH_INVALID_FACE)
            llSay(PUBLIC_CHANNEL, "Sorry, your viewer doesn't support touched faces.");
        else
        {
            // store the original color
            list   colorParams   = llGetLinkPrimitiveParams(link, [PRIM_COLOR, face]);
            vector originalColor = llList2Vector(colorParams, 0);

            // color detected face white
            llSetLinkColor(link, <1.0, 1.0, 1.0>, face);
            llSleep(0.2);

            // color detected face black
            llSetLinkColor(link, ZERO_VECTOR, face);
            llSleep(0.2);

            // color detected face back to original color
            llSetLinkColor(link, originalColor, face);
        }
    }
}

See Also

Deep Notes

History

Search JIRA for related Issues

Signature

function integer llDetectedTouchFace( integer index );