Jump to content

(edge & (CONTROL_LBUTTON)) triggers twice


marcin1995 Sharple
 Share

You are about to reply to a thread that has been inactive for 1493 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello!

I am making a script, that bursts particles for a short amount of time and so far its working good.

My problem is just, that it triggers the particle when i beginn to press LButton and when i release it, which means twice per full click.

Can someone help me to avoid this?

 

this is the control part:

    control(key owner,integer level, integer edge)
    {

        if (edge & (CONTROL_LBUTTON))
        {
            particle();
        llSetTimerEvent(0.5);

        }


    }
    timer()
    {
        particleTriggered = 0;
        stopParticle();
    }

 

I already tried, to work with integer level instead of edge and i can't make it look good like this

Link to comment
Share on other sites

It's reacting to both the edge caused by pressing the button and to the edge caused by releasing the button. To have it react to just the button press, check the level – whether the button is pressed – as well as the edge:

if (edge & (CONTROL_LBUTTON) && level & (CONTROL_LBUTTON))

Edited by KT Kingsley
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

I like to rename "level" and "edge" to "held" and "click" to be more intuitive.

One press of the mouse results in two "clicks." One when you press it initially, and one when you release the button.

The button is "held" during the first click and until the second click happens. (It's not held anymore during the second click.)

if (CONTROL_ML_LBUTTON & click & held)   // click
if (CONTROL_ML_LBUTTON & held)           // held
if (CONTROL_ML_LBUTTON & click & ~held)  // release
if (CONTROL_ML_LBUTTON & ~click & ~held) // not used

 

Edited by Wulfie Reanimator
Link to comment
Share on other sites

32 minutes ago, Wulfie Reanimator said:

 


if (CONTROL_ML_LBUTTON & click & held)   // click
if (CONTROL_ML_LBUTTON & held)           // held
if (CONTROL_ML_LBUTTON & click & ~held)  // release
if (CONTROL_ML_LBUTTON & ~click & ~held) // not used

 

Aren't things going to get a bit wonky if you try to combine conditions like that? For example, if (CONTROL_ML_LBUTTON & click & held) will return TRUE if either click or held are TRUE, as it takes only a single bit to be set for the result to be TRUE.

Using that example, don't you need an expression like if ((CONTROL_LBUTTON & click) && (CONTROL_LBUTTON & held)) or if (CONTROL_LBUTTON & (click | held)) == (click | held))?

Edited by KT Kingsley
Link to comment
Share on other sites

1 hour ago, KT Kingsley said:

Aren't things going to get a bit wonky if you try to combine conditions like that? For example, if (CONTROL_ML_LBUTTON & click & held) will return TRUE if either click or held are TRUE, as it takes only a single bit to be set for the result to be TRUE.

Using that example, don't you need an expression like if ((CONTROL_LBUTTON & click) && (CONTROL_LBUTTON & held)) or if (CONTROL_LBUTTON & (click | held)) == (click | held))?

"CONTROL_ML_LBUTTON & click & held" will not return true if either condition is true. You're confusing & with |. Wear this:

default
{
    control(key id, integer held, integer click)
    {
        string text = "held " + (string)held + " click " + (string)click + "\n";

        if (CONTROL_LBUTTON & click & held)
        {
            text += "click";
        }
        if (CONTROL_LBUTTON & held)
        {
            text += "held";
        }
        if (CONTROL_LBUTTON & click & ~held)
        {
            text += "release";
        }
        if (CONTROL_LBUTTON & ~click & ~held)
        {
            text += "off"; // Won't work with a single button.
        }

        llSetText(text, <1,1,1>, 1);
    }

    changed(integer change)
    {
        if (change & CHANGED_OWNER) llResetScript();
    }

    state_entry()
    {
        if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }

    attach(key id)
    {
        if (id) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }

    run_time_permissions(integer perm)
    {
        if (perm)
        {
            llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
        }
    }
}

To explain just a little bit, "value & value" has a non-zero result only when those values have matching bits, eg.
1000 & 0001 = 0000
1110 & 0111 = 0110
1111 & 0000 = 0000

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1493 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...