如何在Linden Scripting Language中测量鼠标左键的持续时间?

时间:2016-05-01 00:42:52

标签: mouseevent linden-scripting-language

我想用LSL制作一个射击游戏,所以我想测量鼠标左键点击开始和结束之间的时间,以便设置投掷速度。

我还想更新一个gui(或至少显示Power: 55%等文字。)让我们说每增加5%。

我该怎么做?

我真的无法展示我所做的任何事情,因为我不太了解LSL,所以我无法尝试任何事情。我能找到的最近的是llTakeControls的此页面,但我不确定如何使用它。

提前感谢您的帮助,

修改

根据@ BlindWanderer的回答,我尝试修改它(希望在鼠标停止时重复调用control())但显然情况并非如此:

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
        }

    }
}

我的第二次尝试(在意识到有一个名为held的变量之后),但我又无法使其工作:/

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
            }
        }




    }
}

1 个答案:

答案 0 :(得分:1)

从llTakeControls修改示例比解释如何修改示例更快。这是一种快速而肮脏的方式来获得时间。

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());
        }
    }
}