User:Trinity Coulter/Touch and hold example script
Jump to navigation
Jump to search
Example script showing click and hold to take action instead of simple clicking.
<lsl> integer ignore = FALSE; float touch_hold_delay = 1.0; integer touch_held = FALSE;
default {
state_entry()
{
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llSay(0, "Touch_start.");
llSetTimerEvent(touch_hold_delay);
}
touch(integer num_detected)
{
if (ignore == FALSE)
{
llSay(0, "Touching.");
}
if (touch_held == TRUE)
{
// Do something based on this condition
// in the touch event or touch_end event
// depending on needs.
}
}
touch_end(integer total_number)
{
llSay(0, "Touch_end.");
llSetTimerEvent(0.0);
ignore = FALSE;
if (touch_held == TRUE)
{
// Do something based on this condition
// in the touch event or touch_end event
// depending on needs.
}
}
timer()
{
llSay(0,"Timer: touch held for " + (string)touch_hold_delay + " seconds.");
touch_held = TRUE;
ignore = TRUE;
llSetTimerEvent(0.0);
}
} </lsl>