Untitled

 avatar
unknown
plain_text
2 years ago
2.0 kB
8
Indexable
//Set functions for Touch, Click and Long touch; 2.0; 2023.12.19; by Paradox
//
//For detailed instructions, see the example.

//Constants
float double_click_time = 0.3;
float long_click_time = 3.0;

//Variables
integer touch_start_counter;
integer touch_detected;
float touch_time_1;
float touch_time_2;


integer isClick()
{    
    if (touch_start_counter == 1 && touch_detected == 0)
    {
        touch_start_counter = 0;
        llSetTimerEvent(0.0);
        return TRUE;
    }
    else return FALSE;    
}

integer isDoubleClick()
{
    if (touch_start_counter == 2)
    {
        touch_start_counter = 0;
        llSetTimerEvent(0.0);
        return TRUE;    
    }
    else return FALSE;    
}

integer isLongClick()
{
    if (touch_time_2 - touch_time_1 >= long_click_time)
    {
        touch_time_1 = touch_time_2;
        touch_start_counter = 0;
        llSetTimerEvent(0.0);
        return TRUE;    
    }
    else return FALSE;
}

default
{
    touch_start(integer total_number)
    {
        //For clicks
        touch_start_counter += 1;
        if (touch_start_counter == 1)
        {
            llSetTimerEvent(double_click_time);       
            touch_time_1 = llGetTime();
        }
        
        //Double click event 
        if (isDoubleClick() == TRUE)
        {
            llSay(0, "is Double Click");
        }    
    }
    
    touch(integer num_detected)
    {
        //For clicks
        touch_detected = 1;
        if (touch_start_counter == 1)
        {
            touch_time_2 = llGetTime();
        }
        
        //Long click event
        if (isLongClick() == TRUE)
        {
            llSay(0, "is Long Click");    
        }     
    }
    
    touch_end(integer num_detected)
    {
        //For clicks
        touch_detected = 0;  
    }
    
    timer()
    {    
        //Click event
        if (isClick() == TRUE)
        {
            llSay(0, "is Click");    
        }        
    }
}
Editor is loading...
Leave a Comment