Difference between revisions of "LlSetClickAction"

From Second Life Wiki
Jump to navigation Jump to search
(CLICK_ACTION_ZOOM)
 
(24 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Issues/VWR-640}}{{Issues/VWR-10829}}{{LSL_Function
{{LSL_Function
|inject-2={{Issues/VWR-640}}{{Issues/VWR-10829}}
|func_id=333|func_sleep=0.0|func_energy=10.0
|func_id=333|func_sleep=0.0|func_energy=10.0
|func=llSetClickAction
|func=llSetClickAction
|p1_type=integer|p1_name=action|p1_desc=CLICK_ACTION_* flag
|p1_type=integer|p1_subtype=click_action|p1_name=action|p1_desc=CLICK_ACTION_* flag
|func_desc=Sets the action performed when a prim is clicked upon (aka [[click action]]).
|func_desc=Sets the action performed when a prim is clicked upon (aka [[click action]]).
|func_footnote=When the cursor hovers over the prim, its image changes to reflect the action.
|func_footnote=When the cursor hovers over the prim, its image changes to reflect the action.
|caveats= *When set in the root of an object the chosen CLICK_ACTION_* will be that for the children also even if they have their own [[llSetClickAction]] set (it will be over-ridden). However (in the case of [[touch]] for example) if the CLICK_ACTION_* is set in the root but not at all in the children (including not having [[touch]] [[event]] [[script]]s in them (this creates a default CLICK_ACTION_TOUCH)) the effect of the roots CLICK_ACTION_* is not ''seen'' but the CLICK_ACTION_* is ''used'' on clicking. To both use '''and see''' the correct cursor the CLICK_ACTION_* flags must match in the children and root.
|caveats= *When set in the root of an object the chosen CLICK_ACTION_* will be that for the children also even if they have their own [[llSetClickAction]] set (it will be over-ridden). However (in the case of [[touch]] for example) if the CLICK_ACTION_* is set in the root but not at all in the children (including not having [[touch]] [[event]] [[script]]s in them (this creates a default [[CLICK_ACTION_TOUCH]])) the effect of the roots CLICK_ACTION_* is not ''seen'' but the CLICK_ACTION_* is ''used'' on clicking. To both use '''and see''' the correct cursor the CLICK_ACTION_* flags must match in the children and root.
|examples= This is a great way to create a user interface that evolves with the process the script is taking the user through.<lsl>key sitter;
*If [[llSetClickAction]] is [[CLICK_ACTION_PAY]] then you must have a [[money]] event, or it will revert to [[CLICK_ACTION_NONE]].
*While this function works or attached objects (click action can be changed), the configured click action of an attachment is ignored by the viewer (with exceptions).  The viewer always* behaves as though an attached object has [[CLICK_ACTION_TOUCH]] set.
*The only exception to the above rule is when the chosen click action is [[CLICK_ACTION_NONE]], which will disable the cursor changing from the standard pointer arrow to the touch pointer.
* [[llSetClickAction]] has to be called '''before''' an avatar clicks on an object. Calling it while an avatar is clicking (click & holding) will cause this function to silently fail. You ''can'' set the click action after an avatar touches an object, but bear in mind that there may be some delay before the given avatar's viewer will update due to ping times, etc.
|examples={{{!}} width="100%" {{Prettytable}}
{{!}}- {{Hl2}}
! '''make sitting easier'''
! '''make unpacking for next owner easier'''
! '''make buying for customers easier'''
{{!}}- valign="bottom"
{{!!}}<syntaxhighlight lang="lsl2">
default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_SIT);
        llRemoveInventory(llGetScriptName());
    }
}
</syntaxhighlight>
{{!!}}
<syntaxhighlight lang="lsl2">
default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_OPEN);
        llRemoveInventory(llGetScriptName());
    }
}
</syntaxhighlight>
{{!!}}
<syntaxhighlight lang="lsl2">
//  remember you'll have to set a price
//  in the general tab of the edit window
//  for your object before using this script


list up_up_and_away;
default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_BUY);
        llRemoveInventory(llGetScriptName());
    }
}
</syntaxhighlight>
{{!}}}
<syntaxhighlight lang="lsl2">
//  simple tipjar


CoughsAndLolz()
default
{
{
     integer count = 0;
     state_entry()
     vector XYZ = llGetPos();
     {
    float X = XYZ.x;
        llSetClickAction(CLICK_ACTION_PAY);
    float Y = XYZ.y;
 
     do
     //  enabled edit field to put own amount, all quick-pay-buttons hidden
         up_up_and_away = up_up_and_away + [PRIM_POSITION, <X,Y,4000.0>];
         llSetPayPrice(PAY_DEFAULT, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
     while((++count) < 400);
     }
 
    money(key id, integer amount)
    {
        string name = llKey2Name(id);
 
        llInstantMessage(id, "Thank you for the tip, " + name + "!");
    }
}
}
</syntaxhighlight>
<syntaxhighlight lang="lsl2">
//Sit Only with Permission
list gAvWhitelist = ["953d10f1-44ce-462a-8bc1-f634333ee031", "599dce91-a2b8-48c5-b96d-54965433022b"];


default
default
Line 25: Line 85:
     state_entry()
     state_entry()
     {
     {
        llSetClickAction(CLICK_ACTION_SIT); // Set in state entry to be sit on click.
         llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);
         llSitTarget(<0.0,0.0,0.01>, ZERO_ROTATION);
     }
     }
   
     changed(integer change)
     changed(integer change)
     {
     {
         if(change & CHANGED_LINK)
         if (change & CHANGED_LINK)
         {
         {
             sitter = llAvatarOnSitTarget();
             list Properties = llGetObjectDetails(llGetKey(), [OBJECT_CLICK_ACTION]);
             if(sitter)
             integer Click = llList2Integer(Properties, 0);
             { // Someone is upon us.
             key Av = llAvatarOnSitTarget();
                CoughsAndLolz();
            if ((Av != NULL_KEY) && (!Click))
                llSetClickAction(CLICK_ACTION_TOUCH);// And so we change the click action to allow the touch_start.
            {
                 llSay(0, "Click me for a thrill");
                 llSay(0, "Please click first for permission to sit.");
                llUnSit(Av);
             }
             }
         }
         }
     }
     }
     touch_start(integer detected)
     touch_start(integer total_number)
     {
     {
         if(sitter)
        list Properties = llGetObjectDetails(llGetKey(), [OBJECT_CLICK_ACTION]);
        integer Click = llList2Integer(Properties, 0);
         if (!Click && (~llListFindList(gAvWhitelist, [(string)llDetectedKey(0)])))
         {
         {
             llSetLinkPrimitiveParams(LINK_SET, up_up_and_away);
             llSetClickAction(CLICK_ACTION_SIT);
             llUnSit(sitter);
            llSetTimerEvent(10.0);
             llDie();
            llSay(0, "Please take a seat.");
         }      
        }
     }          
        else
}</lsl>
        {
            llSetClickAction(CLICK_ACTION_TOUCH);
            if (llAvatarOnSitTarget() != NULL_KEY)
            {
                llSay(0, "Good bye!");
             }
            else
            {
                llSay(0, "Sorry.  You are not allowed to sit here.");
             }
            llUnSit(llDetectedKey(0));
         }          
    }
   
    timer()
    {
        llSetTimerEvent(0.0);
        llSetClickAction(CLICK_ACTION_TOUCH);
     }
}
</syntaxhighlight>
 
|spec
|spec
|constants=<div id="box">
|constants=<div id="box">
==Constants==
==Constants==
<div style="padding: 0.5em;">
{{LSL Constants/ClickAction}}
{{{!}} class="sortable" {{Prettytable}}
|signature=
{{!}}- {{Hl2}}
{{LSL Const/Signature|CLICK_ACTION_ZOOM|integer|7|c=Zoom}}
! {{!}} Flag
! title="Value" {{!}}
! class="unsortable" {{!}} Description
! class="unsortable" {{!}} Cursor
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_NONE|integer|0|c=Performs the default action: when the prim is touched, touch events are triggered}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}<!--[[Image:]]-->
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_TOUCH|integer|0|c=When the prim is touched, touch events are triggered}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}<!--[[Image:]]-->
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_SIT|integer|1|c=When the prim is touched, the avatar sits upon it}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolsit.png‎]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_BUY|integer|2|c=When the prim is touched, the buy dialog is opened}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolbuy.png]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_PAY|integer|3|c=When the prim is touched, the pay dialog is opened}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolpay.png]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_OPEN|integer|4|c=When the prim is touched, the object inventory dialog is opened}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolopen.png]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_PLAY|integer|5|c=Play or pause parcel media on touch}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolplay.png]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_OPEN_MEDIA|integer|6|c=Play parcel media on touch, no pause}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}}
{{!}}[[Image:Toolmediaopen.png]]
{{!}}-
{{!}}{{LSL Const|CLICK_ACTION_ZOOM|integer|7|c=Zoom}}
{{!}}{{#var:value}}
{{!}}{{#var:comment}} ([[Viewer_2_Help|Viewer 2]])
{{!}}[[Image:Toolzoom.png]]
{{!}}}
</div></div>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llPassTouches]]}}
|also_functions={{LSL DefineRow||[[llPassTouches]]}}
Line 116: Line 149:
{{LSL DefineRow||[[touch_end]]}}
{{LSL DefineRow||[[touch_end]]}}
|also_articles={{LSL DefineRow||{{LSLGC|Detected}}}}
|also_articles={{LSL DefineRow||{{LSLGC|Detected}}}}
|notes=With the CLICK_ACTION_* flag set to anything but [[CLICK_ACTION_NONE]] or [[CLICK_ACTION_TOUCH]] (default), the script won't trigger the {{LSLGC|Touch|touch* events}} anymore when the prim is clicked.
|deepnotes=*When using [[CLICK_ACTION_SIT]], an avatar who clicks the object and sits down and then clicks the object again will fire a [[touch]] event with the second click.
|history=
|history=
* Introduced in SL Client 1.19.1(0)
* Introduced in SL Client 1.19.1(0)
Line 126: Line 159:
|cat5=Media
|cat5=Media
|cat6=Effects
|cat6=Effects
|cat7
|cat7=Click Action
|cat8
|cat8
}}
}}

Latest revision as of 14:11, 16 January 2024

Summary

Function: llSetClickAction( integer action );
0.0 Forced Delay
10.0 Energy

Sets the action performed when a prim is clicked upon (aka click action).

• integer action CLICK_ACTION_* flag

When the cursor hovers over the prim, its image changes to reflect the action.

Constants

Flag Description Cursor
CLICK_ACTION_NONE 0 Performs the default action: when the prim is touched, touch events are triggered
CLICK_ACTION_TOUCH 0 When the prim is touched, touch events are triggered
CLICK_ACTION_SIT 1 When the prim is touched, the avatar sits upon it SitActionCursor.png
CLICK_ACTION_BUY 2 When the prim is touched, the buy dialog is opened SaleOneclickCursor.png
CLICK_ACTION_PAY 3 When the prim is touched, the pay dialog is opened SaleOneclickCursor.png
CLICK_ACTION_OPEN 4 When the prim is touched, the object inventory dialog is opened OpenOneclickCursor.png
CLICK_ACTION_PLAY 5 Play or pause parcel media on touch Toolplay.png
CLICK_ACTION_OPEN_MEDIA 6 Play parcel media on touch, no pause Toolmediaopen.png
CLICK_ACTION_ZOOM 7 Zoom the avatar camera on this object (Viewer 2) Toolzoom.png
CLICK_ACTION_DISABLED 8 No click action. No touches detected or passed.
CLICK_ACTION_IGNORE 9 Clicks go through the object to whatever is behind it. No touches detected.

Caveats

  • When set in the root of an object the chosen CLICK_ACTION_* will be that for the children also even if they have their own llSetClickAction set (it will be over-ridden). However (in the case of touch for example) if the CLICK_ACTION_* is set in the root but not at all in the children (including not having touch event scripts in them (this creates a default CLICK_ACTION_TOUCH)) the effect of the roots CLICK_ACTION_* is not seen but the CLICK_ACTION_* is used on clicking. To both use and see the correct cursor the CLICK_ACTION_* flags must match in the children and root.
  • If llSetClickAction is CLICK_ACTION_PAY then you must have a money event, or it will revert to CLICK_ACTION_NONE.
  • While this function works or attached objects (click action can be changed), the configured click action of an attachment is ignored by the viewer (with exceptions). The viewer always* behaves as though an attached object has CLICK_ACTION_TOUCH set.
  • The only exception to the above rule is when the chosen click action is CLICK_ACTION_NONE, which will disable the cursor changing from the standard pointer arrow to the touch pointer.
  • llSetClickAction has to be called before an avatar clicks on an object. Calling it while an avatar is clicking (click & holding) will cause this function to silently fail. You can set the click action after an avatar touches an object, but bear in mind that there may be some delay before the given avatar's viewer will update due to ping times, etc.

Examples

make sitting easier make unpacking for next owner easier make buying for customers easier
default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_SIT);
        llRemoveInventory(llGetScriptName());
    }
}
default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_OPEN);
        llRemoveInventory(llGetScriptName());
    }
}
//  remember you'll have to set a price
//  in the general tab of the edit window
//  for your object before using this script

default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_BUY);
        llRemoveInventory(llGetScriptName());
    }
}
//  simple tipjar

default
{
    state_entry()
    {
        llSetClickAction(CLICK_ACTION_PAY);

    //  enabled edit field to put own amount, all quick-pay-buttons hidden
        llSetPayPrice(PAY_DEFAULT, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
    }

    money(key id, integer amount)
    {
        string name = llKey2Name(id);

        llInstantMessage(id, "Thank you for the tip, " + name + "!");
    }
}
//Sit Only with Permission

list gAvWhitelist = ["953d10f1-44ce-462a-8bc1-f634333ee031", "599dce91-a2b8-48c5-b96d-54965433022b"];

default
{
    state_entry()
    {
        llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);
    }
    
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            list Properties = llGetObjectDetails(llGetKey(), [OBJECT_CLICK_ACTION]);
            integer Click = llList2Integer(Properties, 0);
            key Av = llAvatarOnSitTarget();
            if ((Av != NULL_KEY) && (!Click))
            {
                llSay(0, "Please click first for permission to sit.");
                llUnSit(Av);
            }
        }
    }
    touch_start(integer total_number)
    {
        list Properties = llGetObjectDetails(llGetKey(), [OBJECT_CLICK_ACTION]);
        integer Click = llList2Integer(Properties, 0);
        if (!Click && (~llListFindList(gAvWhitelist, [(string)llDetectedKey(0)])))
        {
            llSetClickAction(CLICK_ACTION_SIT);
            llSetTimerEvent(10.0);
            llSay(0, "Please take a seat.");
        }
        else
        {
            llSetClickAction(CLICK_ACTION_TOUCH);
            if (llAvatarOnSitTarget() != NULL_KEY)
            {
                llSay(0, "Good bye!");
            }
            else
            {
                llSay(0, "Sorry.  You are not allowed to sit here.");
            }
            llUnSit(llDetectedKey(0));
        }            
    }
    
    timer()
    {
        llSetTimerEvent(0.0);
        llSetClickAction(CLICK_ACTION_TOUCH);
    }
}

See Also

Events

•  touch_start
•  touch
•  touch_end

Functions

•  llPassTouches

Articles

•  Detected

Deep Notes

  • When using CLICK_ACTION_SIT, an avatar who clicks the object and sits down and then clicks the object again will fire a touch event with the second click.

History

Signature

function void llSetClickAction( integer action );
integer CLICK_ACTION_ZOOM = 7;//Zoom