Script switch needed

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Script switch needed // Interactive Artwork

1  |  

Post by bill // Aug 27, 2006, 4:26pm

bill
Total Posts: 114
pic
Ok, I am almost complete with my engine design animation. All that is left is one script that I need to get working correctly. The formulas I have written work as I want them to but I need a way to switch between formulas.

This is what I have. txA is an input linked to another node. link_angle is the output result from this script. What I want to do is to make a toggle switch that causes one of two formulas to be used for the link_angle result.

At a certain point in the animation txA will equal -6.0000023842. When this happens I want to trip the toggle switch. When txA reaches -6.0000023842 again I want the toggle switch to switch back, and so on each time txA equals -6.0000023842.

This is my attampt at this but so far I have not got it to work properly. Any clues what I'm missing? As mentioned in a previous post I'm not a programmer. I just pound code into place with a hammer until it works...or until my computer fries...whichever happens first.

function OnComputeOutputs(params)
{
txA = params.conValue('txA');

if (txA = -6.0000023842)
flip = flip * -1; // this toggles the value of flip between 1 and -1
else
flip = flip;

if (flip = 1)
aValue = (Math.acos(Math.abs(txA)/6.0000028611)/Math.PI*180)+270; //formula if flip = 1
else
aValue = (Math.acos(Math.abs(txA)/-6.0000028611)/Math.PI*180)+90; //formula if flip = -1

params.conValue("link_angle") = aValue;
}

Post by Délé // Aug 27, 2006, 5:02pm

Délé
Total Posts: 1374
pic
Hey Bill,


There is a toggle switch that comes with the Procedural Animation course. Not sure if that will help or not. Though I think the only problem with your script, so far as I can see, is that you are using one = instead of two == to check for equality. Also, it looks like you're trying to define "flip" with "flip". I don't see any initial input defining what "flip" is. I can't make any promises but I think this would work (I highlighted the things I changed in blue):


function OnComputeOutputs(params)

{

txA = params.conValue('txA');


if (txA == -6.0000023842)

flip = 1 * -1; // this toggles the value of flip between 1 and -1

else

flip = 1;


if (flip == 1)

aValue = (Math.acos(Math.abs(txA)/6.0000028611)/Math.PI*180)+270; //formula if flip = 1

else

aValue = (Math.acos(Math.abs(txA)/-6.0000028611)/Math.PI*180)+90; //formula if flip = -1


params.conValue("link_angle") = aValue;

}


hth

Post by bill // Aug 27, 2006, 5:21pm

bill
Total Posts: 114
pic
function OnComputeOutputs(params)
{
txA = params.conValue('txA');

if (txA == -6.0000023842)
flip = 1 * -1; // this toggles the value of flip between 1 and -1
else
flip = 1;

if (flip == 1)
aValue = (Math.acos(Math.abs(txA)/6.0000028611)/Math.PI*180)+270; //formula if flip = 1
else
aValue = (Math.acos(Math.abs(txA)/-6.0000028611)/Math.PI*180)+90; //formula if flip = -1

params.conValue("link_angle") = aValue;
}

hth

Hey Délé.

At least part of what you gave me is not what I'm trying to do. This needs to be a toggle switch. It appears to me that your code would give flip a value of -1 only when txA = -6.0000023842. Otherwise flip =1. What I need is something like this:

check the value of txA. If txA = -6.0000023842 then multiply the value of flip by -1 and assign the resulting value to the variable flip(this toggles the value of flip between 1 and -1). If txA <> -6.0000023842 then do not change the value of flip. Thus every time txA = -6.0000023842 the value of flip toggles between 1 and -1 and then remains unchanged until txA = -6.0000023842 again.

Then evaluate the value of flip. If flip = 1 then use the first formula. If flip = -1 then use the other formula.

Am I making sense?

Post by chamaeleon // Aug 27, 2006, 6:52pm

chamaeleon
Total Posts: 74
I would just like to state that I would be extremely reluctant to rely upon a comparison with a floating point value in such a manner. I would really recommend checking to see if the absolute difference between txA and the 6.nnn value is less than some small/epsilon value.

Post by Asem // Aug 27, 2006, 7:28pm

Asem
Total Posts: 255
Where is flip supposed to get its input if you go "flip = flip*-1"? It could work if flip defined globally is set to 1 or -1 first.

Post by Délé // Aug 27, 2006, 7:29pm

Délé
Total Posts: 1374
pic
Ah, I see. I was thinking -6.0000023842 was a pretty specific number to have it change on. :) Well, I think I know how to do what you're wanting but it's hard for me to be specific without knowing exactly what all is going on with "txA".

You must have a script that is creating that changing "txA" number right? I'm thinking that if you make a copy of that script, filter the timer through a speed controller to reduce the speed by half, and filter that into the second "copied" script, then you'll have that same changing "txA" number except it will be twice as slow. Then you should be able to link that into this new script and use a greater than or less than statement to make the toggle. The reason I'm suggesting this method is so that you have twice as much time with "txA" so you can then perform some math to get your target number in the middle of its cycle, thus allowing you to use a greater than or less than statement.

Am I making sense? This stuff can be very hard to articulate, lol.

Post by bill // Aug 28, 2006, 1:35am

bill
Total Posts: 114
pic
Ok...maybe I'm not taking the right approach or there is a better way to do what I am wanting to do.

txA is the exact tx location of a specific object as this object travels in a circular path. At a specific point in the path of this object tx always equals -6.0000023842. The two different formulas I want to toggle between set the angular inclination of another object as it travels around this same path with the first object.

The anmiation is controlled with a timer. Between the timer and the engine is a speed controller that allows me to vary the speed of the animation, in this case the rotations per minute (rpm's) of the engine. I want to use one formula for a period of time and then the other formula for a period of time. But since I can adjust the RPM's of the animation, this period of time varies with the RPM's. To further complicate things, this whole process is happening 5 times per cycle with 5 different objects so each object has its own set of formulas attached to it.

Are you confused yet? The animation is quite complex and uses links between locations of objects to position other objects, essentially creating a procedurally calculated bone structure that ties all the components together to create a working animation of a complex engine animation. I would upload the engine to show you how it all works but since I intend to patent this engine design I don't want to release it out to the public yet.

So, all I'm needing to complete the animation is a toggle that when txA reaches -6.0000023842 the calculation uses formula 'A' and continues to use formula 'A' to generate output to another object until txA again reaches -6.0000023842. The calculation then uses formula 'B' to generate output until once again txA reaches -6.0000023842. This happens over and over again during the animation and it is happening 5 times with 5 different objects.

Post by stan // Aug 28, 2006, 4:26am

stan
Total Posts: 1240
pic
Bill, this is probably wrong but this is something I would try..:D

if (txA == -6.0000023842 && flip == -1)
flip = 1;
if (flip = 1)
aValue = (Math.acos(Math.abs
(txA)/6.0000028611)/Math.PI*180)+270; //formula if flip = 1

if (txA == -6.0000023842 && flip == 1)
flip = -1;
if (flip = -1)
aValue = (Math.acos(Math.abs(txA)/-6.0000028611)/Math.PI*180)+90; //formula if flip = -1

Post by bill // Aug 28, 2006, 5:13am

bill
Total Posts: 114
pic
Thanks Stan. I'll give it a try when I get home this evening.

Post by frootee // Aug 28, 2006, 5:19am

frootee
Total Posts: 2667
pic
deleted... same thing as stan recommended...
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn