Jump to content
Tattooshop

Toggle without a toggle?!

Recommended Posts

Hello! I made such a toggle and I need to simplify or maybe get rid of a toggle at all, because the only change here is a " - " symbol. I mean in "mathematical way".

 

Is this possible and how? :)

    touch_start(integer total_number)
    {
            llPlaySound(DOOR_SOUND, VOL);
            toggle = !toggle;

            if (toggle)
            {
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL]), 0) + < 1.0, 0.0, 0.0 >]);
            }

            else
            {
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL]), 0) + < -1.0, 0.0, 0.0 >]);
            }
    }

 

Share this post


Link to post
Share on other sites

Well, you could do something like this:

llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL]), 0) + <-1.0 + (2 * toggle), 0.0, 0.0 >]);

where the x component in the vector is replaced by -1 + (2 * toggle).

  • Thanks 1

Share this post


Link to post
Share on other sites

can also do

toggle = -toggle;

float toggle = 1.0;//can keep as integer you want, but it's being converted to a float in the vector anyways
default
{
    touch_start(integer total_number)
    {
        llPlaySound(DOOR_SOUND, VOL);
        toggle = -toggle;
        llSetLinkPrimitiveParamsFast(LINK_THIS, 
        [PRIM_POS_LOCAL, 
        llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, 
        [PRIM_POS_LOCAL]), 0) + <toggle, 0.0, 0.0 >]);
    }
}

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Much better. Even when I posted my reply, I knew there was a better way of doing it. My brain is seizing up.

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, Tattooshop said:

@KT Kingsley @Ruthven Ravenhurst

Thank you so much! You already helped me a lot! But what if the value of X is not 1 but 0.6 for example? :)

 

multiply 0.6 by toggle

toggle = -toggle

<toggle * 0.6, 0.0, 0.0>

 

  • Thanks 1

Share this post


Link to post
Share on other sites
1 minute ago, Mollymews said:

multiply 0.6 by toggle

toggle = -toggle

<toggle * 0.6, 0.0, 0.0>

 

Genius! Thanks! :D

 

Share this post


Link to post
Share on other sites
1 minute ago, Tattooshop said:

Genius! Thanks! :D

 

or even more simply change the value of toggle to 0.6

toggle = -toggle

0.6 = -0.6

-0.6 = 0.6

  • Thanks 1

Share this post


Link to post
Share on other sites

A slightly different approach

float fToggle = 1.0;

default
{

    touch_start(integer total_number)
    {
         fToggle *= -1.0;
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [
            PRIM_POS_LOCAL]), 0) + <fToggle, 0.0, 0.0 >
            ]);
    }
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
40 minutes ago, Innula Zenovka said:

A slightly different approach


float fToggle = 1.0;

default
{

    touch_start(integer total_number)
    {
         fToggle *= -1.0;
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [
            PRIM_POS_LOCAL]), 0) + <fToggle, 0.0, 0.0 >
            ]);
    }
}

 

And an even more slightly different approach, burying the modification of fToggle in the usage of it...

float fToggle = 1.0;

default
{
    touch_start(integer total_number)
    {
         fToggle *= -1.0;
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_POS_LOCAL, llList2Vector(llGetLinkPrimitiveParams(LINK_THIS, [
            PRIM_POS_LOCAL]), 0) + <(fToggle *= -1.0), 0.0, 0.0 >
            ]);
    }
}

 

Edited by Madelaine McMasters
Cuz Innula read what I wrote, and I didn't!
  • Thanks 1

Share this post


Link to post
Share on other sites

I think you need to take out the first inversion of fToggle if you're doing it inside the llSetPP* call.   Otherwise it never actually changes.

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, Innula Zenovka said:

I think you need to take out the first inversion of fToggle if you're doing it inside the llSetPP* call.   Otherwise it never actually changes.

Yep, done!

  • Like 2

Share this post


Link to post
Share on other sites

Continuing with the variations on a theme:

integer toggle;

default
{
    touch_start (integer count)
    {
        llSetLinkPrimitiveParamsFast (LINK_THIS, 
        [
            PRIM_POS_LOCAL, llList2Vector (llGetLinkPrimitiveParams (LINK_THIS, [PRIM_POS_LOCAL]), 0) 
                + <llList2Float ([1.0, -1.0], toggle = !toggle), 0.0, 0.0>
        ]);
    }
}

This uses the variable toggle as a selector in the llList2Float function. Overkill in this example, but it's a technique that can be useful with varables and situations that don't lend temselves to neat mathematical manipulation.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
7 hours ago, KT Kingsley said:

Overkill in this example, but it's a technique that can be useful with varables and situations that don't lend temselves to neat mathematical manipulation.

This is the sort of situation when using your technique starts to come into its own, and the longer the list of parameters, the more useful it is.

integer iToggle;
list lPositions =[<0.0,0.0,0.0>,<1.0,-2.0,0.5>];
list lRotations = [<0.0,0.0,0.0,1.0>,<-0.0, 0.0, -1.0, 0.0>];//0 and 180 degrees
vector vPos;
default
{
    state_entry()
    {
        vPos = llGetLocalPos();
    }

    on_rez(integer start_param)
    {
        llResetScript();
    }

    touch_start(integer total_number)
    {
        iToggle=!iToggle;
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_POS_LOCAL,vPos+ llList2Vector(lPositions,iToggle),
            PRIM_ROT_LOCAL,llList2Rot(lRotations,iToggle)
                ]);
    }
}

  

  • Thanks 1

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