Jump to content
marcin1995 Sharple

(edge & (CONTROL_LBUTTON)) triggers twice

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
Share on other sites
Posted (edited)

Yeah, sorry, you're right. I was confusing this with the situation with permissions and changes, which is completely different.

Edited by KT Kingsley

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...