# Toggle without a toggle?!

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

else
{
}
}```

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

• 1
##### 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;
[PRIM_POS_LOCAL,
[PRIM_POS_LOCAL]), 0) + <toggle, 0.0, 0.0 >]);
}
}```

• 2
• 1
##### 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.

• 1
##### Share on other sites

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?

##### Share on other sites

8 minutes ago, Tattooshop said:

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>

• 1
##### 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!

##### Share on other sites

1 minute ago, Tattooshop said:

Genius! Thanks!

or even more simply change the value of toggle to 0.6

toggle = -toggle

0.6 = -0.6

-0.6 = 0.6

• 1
##### Share on other sites

A slightly different approach

```float fToggle = 1.0;

default
{

touch_start(integer total_number)
{
fToggle *= -1.0;
PRIM_POS_LOCAL]), 0) + <fToggle, 0.0, 0.0 >
]);
}
}```

• 1
##### 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;
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;
PRIM_POS_LOCAL]), 0) + <(fToggle *= -1.0), 0.0, 0.0 >
]);
}
}```

Cuz Innula read what I wrote, and I didn't!
• 1
##### 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.

• 1
##### 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!

• 2
##### Share on other sites

Continuing with the variations on a theme:

```integer toggle;

default
{
touch_start (integer count)
{
[
+ <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.

• 2
• 1
##### 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;
PRIM_POS_LOCAL,vPos+ llList2Vector(lPositions,iToggle),
PRIM_ROT_LOCAL,llList2Rot(lRotations,iToggle)
]);
}
}```

• 1
##### Share on other sites

Thank you all very much! Now I have so many options!

##### Share on other sites

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