Difference between revisions of "LlDetectedTouchFace"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(14 intermediate revisions by 7 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
|return_type=integer|return_text=that is the index of the face the avatar clicked on.
|return_type=integer|return_text=that is the index of the face the avatar clicked on.
|p1_type=integer|p1_name=index
|p1_type=integer|p1_name=index
|func_footnote=For the {{LSLGC|Touch|touch}} category of events only.
|func_footnote=For the {{LSLGC|Touch|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.
|func_desc
|func_desc
|spec
|spec
|caveats=
|caveats=
'''{{LSL Const|TOUCH_INVALID_FACE|integer|-1}} is returned when...'''
*{{LSL Const|TOUCH_INVALID_FACE|integer|-1}} is returned when...
* The avatar's viewer does not support face touch detection.
** The avatar's viewer does not support face touch detection.
* The touch has moved off the surface of the prim.
** The touch has moved off the surface of the prim.
* The triggering event is not a 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 57: Line 85:
|also_articles
|also_articles
|notes
|notes
|history=*Introduced in Viewer {{SVN|870|rev=92872|branch=Release|anchor=file14|date=Wednesday, 23 July 2008}}, no server support, no viewer binary released.
|history=*Introduced in Viewer {{SVN|870|rev=92872|branch=Release|anchor=file14|date=Wednesday, 23 July 2008}}.
*Server support available on preview grid in Second Life Beta Server 1.24, client support in Preview Grid viewer 1.20.15 (93532)
*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
|cat2=Face
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 23:58, 21 January 2015

Summary

Function: integer llDetectedTouchFace( integer index );
0.0 Forced Delay
10.0 Energy

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.

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

Signature

function integer llDetectedTouchFace( integer index );