Jump to content

Toggle without a toggle?!


Tattooshop
 Share

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

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

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

 

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1426 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...