1

I want to make a shooter with LSL, so I want to measure the time between the start and the end of a left mouse click, in order to set throw velocity.

I also want to update a gui (or at least display the text like Power: 55% etc.) let's say at each 5% increment.

How can I do that?

I really can't show anything I have done because I don't know LSL much, so I couldn't try anything. The closest I could find is this page for llTakeControls, but I'm not sure how to use it.

Thanks in advance for any help,

Edit

Based on @BlindWanderer's answer, I tried to modify it (hoping that control() would get repeatedly called while mouse is down) but apparently this is not the case:

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }
    run_time_permissions(integer perm)
    {
        if(PERMISSION_TAKE_CONTROLS & perm)
        {
            llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
        }
    }
    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);
        if(start & CONTROL_LBUTTON) {
            llResetTime();
        }
        if(end & CONTROL_LBUTTON) {
            llOwnerSay((string)llGetTime());
        }
        // --- My attempt to display the time peridoically
        float timerval = llGetTime();
        llOwnerSay((string)timerval); // this doesn t fire
        if(llRound(timerval*100) % 5 == 0){
            llOwnerSay((string)timerval); // this neither
        }

    }
}

My 2nd attempt (after realizing there is a variable called held), but again I couldn't make it work :/

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }
    run_time_permissions(integer perm)
    {
        if(PERMISSION_TAKE_CONTROLS & perm)
        {
            llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
        }
    }
    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);
        if(start & CONTROL_LBUTTON) {
            llResetTime();
        }
        if(end & CONTROL_LBUTTON) {
            llOwnerSay((string)llGetTime());
        }

        if(held & CONTROL_LBUTTON){
            llOwnerSay("check");
            float timerval = llGetTime();
            llOwnerSay((string)timerval); // this doesn t fire
            if(llRound(timerval*100) % 5 == 0){
                llOwnerSay((string)timerval); // this neither
            }
        }




    }
}
Jack Pot
  • 21
  • 2

1 Answers1

1

It was quicker to modify the example from llTakeControls than to explain how to modify the example. Here is a quick and dirty way to get the time.

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }
    run_time_permissions(integer perm)
    {
        if(PERMISSION_TAKE_CONTROLS & perm)
        {
            llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
        }
    }
    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);
        if(start & CONTROL_LBUTTON) {
            llResetTime();
        }
        if(end & CONTROL_LBUTTON) {
            llOwnerSay((string)llGetTime());
        }
    }
}
  • This looks like just what I need! I will try and let you know ASAP. Thanks, – Jack Pot May 01 '16 at 20:54
  • It measures the time correctly (just `;`'s missing in the last two `ll..` functions), but I want it to update (say another line) regularly as I'm holding the mouse down. I'm pasting my attempt in the question. Thanks again, – Jack Pot May 01 '16 at 21:09