Tattooshop Posted May 19, 2020 Share Posted May 19, 2020 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 More sharing options...
KT Kingsley Posted May 19, 2020 Share Posted May 19, 2020 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 Link to comment Share on other sites More sharing options...
Ruthven Ravenhurst Posted May 20, 2020 Share Posted May 20, 2020 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 >]); } } 2 1 Link to comment Share on other sites More sharing options...
KT Kingsley Posted May 20, 2020 Share Posted May 20, 2020 Much better. Even when I posted my reply, I knew there was a better way of doing it. My brain is seizing up. 1 Link to comment Share on other sites More sharing options...
Tattooshop Posted May 20, 2020 Author Share Posted May 20, 2020 @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? Link to comment Share on other sites More sharing options...
Mollymews Posted May 20, 2020 Share Posted May 20, 2020 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> 1 Link to comment Share on other sites More sharing options...
Tattooshop Posted May 20, 2020 Author Share Posted May 20, 2020 1 minute ago, Mollymews said: multiply 0.6 by toggle toggle = -toggle <toggle * 0.6, 0.0, 0.0> Genius! Thanks! Link to comment Share on other sites More sharing options...
Mollymews Posted May 20, 2020 Share Posted May 20, 2020 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 Link to comment Share on other sites More sharing options...
Innula Zenovka Posted May 20, 2020 Share Posted May 20, 2020 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 > ]); } } 1 Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted May 20, 2020 Share Posted May 20, 2020 (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 May 20, 2020 by Madelaine McMasters Cuz Innula read what I wrote, and I didn't! 1 Link to comment Share on other sites More sharing options...
Innula Zenovka Posted May 20, 2020 Share Posted May 20, 2020 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 Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted May 20, 2020 Share Posted May 20, 2020 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 Link to comment Share on other sites More sharing options...
KT Kingsley Posted May 20, 2020 Share Posted May 20, 2020 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. 2 1 Link to comment Share on other sites More sharing options...
Innula Zenovka Posted May 20, 2020 Share Posted May 20, 2020 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) ]); } } 1 Link to comment Share on other sites More sharing options...
Tattooshop Posted May 21, 2020 Author Share Posted May 21, 2020 Thank you all very much! Now I have so many options! Link to comment Share on other sites More sharing options...
Recommended Posts
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